Search in sources :

Example 1 with IdMapQuery

use of me.botsko.prism.database.IdMapQuery in project Prism-Bukkit by prism.

the class MaterialAliases method getIdsOf.

private Set<IntPair> getIdsOf(Material material) {
    Set<IntPair> ids = allIdsCache.get(material);
    if (ids != null) {
        return ids;
    }
    IdMapQuery query = new SqlIdMapQuery(Prism.getPrismDataSource());
    query.findAllIds(material.name().toLowerCase(Locale.ENGLISH), list -> allIdsCache.put(material, new HashSet<>(list)));
    return allIdsCache.get(material);
}
Also used : IdMapQuery(me.botsko.prism.database.IdMapQuery) SqlIdMapQuery(me.botsko.prism.database.sql.SqlIdMapQuery) SqlIdMapQuery(me.botsko.prism.database.sql.SqlIdMapQuery) HashSet(java.util.HashSet)

Example 2 with IdMapQuery

use of me.botsko.prism.database.IdMapQuery in project Prism-Bukkit by prism.

the class MaterialAliases method partialBlockDataIds.

/**
 * .
 *
 * @param material         Material
 * @param partialBlockData String
 * @return Set of IntPair
 * @throws IllegalArgumentException exception
 */
public Set<IntPair> partialBlockDataIds(Material material, String partialBlockData) throws IllegalArgumentException {
    String fullBlockData = Utilities.dataString(Bukkit.createBlockData(material, partialBlockData));
    String[] parts = fullBlockData.substring(1, fullBlockData.length() - 1).toLowerCase(Locale.ENGLISH).split(",");
    StringBuilder likeString = new StringBuilder("%");
    for (String string : parts) {
        if (partialBlockData.contains(string)) {
            likeString.append(string).append('%');
        }
    }
    String stateLike = likeString.toString();
    IdMapQuery query = new SqlIdMapQuery(Prism.getPrismDataSource());
    Set<IntPair> ids = new HashSet<>();
    query.findAllIdsPartial(material.name().toLowerCase(Locale.ENGLISH), stateLike, ids::addAll);
    return ids;
}
Also used : IdMapQuery(me.botsko.prism.database.IdMapQuery) SqlIdMapQuery(me.botsko.prism.database.sql.SqlIdMapQuery) SqlIdMapQuery(me.botsko.prism.database.sql.SqlIdMapQuery) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 IdMapQuery (me.botsko.prism.database.IdMapQuery)2 SqlIdMapQuery (me.botsko.prism.database.sql.SqlIdMapQuery)2