Пример #1
0
 /**
  * 看板IDから評価看板を返す
  *
  * @param signID
  * @return LikeSign or null
  */
 public static LikeSign getLikeSignBySignID(int signID) {
   for (LikeSign ls : signs.values()) {
     if (ls.getSignID() == signID) {
       return ls;
     }
   }
   return null; // not found
 }
Пример #2
0
 public static int saveAll() {
   int i = 0;
   for (LikeSign ls : signs.values()) {
     ls.save();
     i++;
   }
   return i;
 }
Пример #3
0
 /**
  * 建築者名と看板名から評価看板を返す
  *
  * @param creator
  * @param signName
  * @return LikeSign or null
  */
 public static LikeSign getLikeSignByCreatorAndName(String creator, String signName) {
   for (LikeSign ls : signs.values()) {
     if (ls.getCreator().equalsIgnoreCase(creator) && ls.getName().equalsIgnoreCase(signName)) {
       return ls;
     }
   }
   return null;
 }
Пример #4
0
  /**
   * 建築者の評価看板リストを返す
   *
   * @param creator
   * @return List<LikeSign>
   */
  public static List<LikeSign> getLikeSignsByCreator(String creator) {
    List<LikeSign> ret = new ArrayList<LikeSign>();

    for (LikeSign ls : signs.values()) {
      if (ls.getCreator().equalsIgnoreCase(creator)) {
        ret.add(ls);
      }
    }

    return ret;
  }
Пример #5
0
  /** データベースから看板データをマッピングする */
  public static int loadSigns() {
    signs.clear();
    World world;
    Location loc;

    Database database = LikesPlugin.getDatabases();
    final String tablePrefix = LikesPlugin.getInstance().getConfigs().getMySQLtablePrefix();

    HashMap<Integer, ArrayList<String>> result =
        database.read(
            "SELECT `sign_id`, `sign_name`, `player_name`, `status`, `text`, `liked`, `lastliked`, `created`, `world`, `x`, `y`, `z` "
                + "FROM "
                + tablePrefix
                + "signs NATURAL JOIN "
                + tablePrefix
                + "users");
    for (ArrayList<String> record : result.values()) {
      int signID = Integer.parseInt(record.get(0));

      world = Bukkit.getWorld(record.get(8));
      if (world == null) {
        log.warning(
            logPrefix + "Skipping SignID " + record.get(0) + ":not exist world " + record.get(1));
        continue;
      }

      loc =
          new Location(
              world,
              Double.parseDouble(record.get(9)),
              Double.parseDouble(record.get(10)),
              Double.parseDouble(record.get(11)));

      LikeSign ls =
          new LikeSign(
              signID,
              record.get(1),
              record.get(2),
              Integer.parseInt(record.get(3)),
              record.get(4),
              Integer.parseInt(record.get(5)),
              Long.parseLong(record.get(6)),
              Long.parseLong(record.get(7)),
              loc);

      ls.updateSign();
      // Add HashMap
      signs.put(loc, ls);
    }
    return signs.size();
  }
Пример #6
0
  /**
   * 新規評価看板をDBに登録する
   *
   * @param sign
   * @param creator
   * @param sign_name
   * @param description
   * @return
   */
  public static boolean createSign(
      final Sign sign, final Player creator, final String sign_name, final String description) {
    if (sign == null || sign.getBlock() == null || creator == null || sign_name == null) {
      return false;
    }

    final Location loc = sign.getBlock().getLocation();

    LikeSign ls =
        new LikeSign(
            0, sign_name, creator.getName(), 0, description, 0, 0, Util.getCurrentUnixSec(), loc);
    ls.save(true); // INSERT

    // Add
    signs.put(loc, ls);
    return true;
  }