Compare commits

..

No commits in common. "666c45735db43f169e05e7a8eda8d3633a1a2196" and "8c04009c66a92f92894a3c9c920af1378e72ad5f" have entirely different histories.

3 changed files with 8 additions and 26 deletions

View file

@ -33,14 +33,13 @@ public class FavoriteAppearanceEntryItem extends AsyncItem {
}, (_ -> true)).getItemProvider(),
() -> {
try {
// TODO (Ineanto, 08/06/2025): set a default skin if the entry contains only a name
final String name = (appearance.name() == null ? "N/A" : appearance.name());
final String skin = (appearance.skin() == null ? "N/A" : appearance.skin());
final String name = (appearance.name() == null ? appearance.skin() : appearance.name());
final String skin = (appearance.skin() == null ? appearance.name() : appearance.skin());
final SkullBuilder skull = new SkullBuilder(skin);
return playerLanguage.translateItem(skull, LanguageKey.GUI.Admin.Cache.ENTRY, name);
} catch (MojangApiUtils.MojangApiException | IOException e) {
Nicko.getInstance().getLogger().warning("Unable to get Head texture for specified UUID (" + appearance.skin() + ")! (GUI/Favorites/Entry)");
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Admin.Cache.ENTRY, "...");
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Admin.Cache.ENTRY, Nicko.getInstance().getMojangAPI().getUUIDName("Notch"));
}
});
this.playerLanguage = playerLanguage;

View file

@ -1,8 +1,5 @@
package xyz.ineanto.nicko.storage.mariadb;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import xyz.ineanto.nicko.appearance.ActionResult;
import xyz.ineanto.nicko.appearance.Appearance;
import xyz.ineanto.nicko.config.Configuration;
@ -15,7 +12,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.logging.Logger;
@ -23,7 +19,6 @@ import java.util.logging.Logger;
public class MariaDBStorage extends Storage {
private final Logger logger = Logger.getLogger("SQLStorage");
private final Configuration configuration;
private final Gson gson = new GsonBuilder().serializeNulls().create();
private MariaDBStorageProvider provider;
@ -91,17 +86,15 @@ public class MariaDBStorage extends Storage {
String skin = "";
String locale = "";
boolean randomSkin = false;
List<Appearance> favorites = Collections.emptyList();
while (resultSet.next()) {
name = resultSet.getString("name");
skin = resultSet.getString("skin");
locale = resultSet.getString("locale");
randomSkin = resultSet.getBoolean("randomskin");
favorites = gson.fromJson(resultSet.getString("favorites"), new TypeToken<List<Appearance>>() { }.getType());
}
// TODO (Ineanto, 17/05/2025): Retrieve favorites
final NickoProfile profile = new NickoProfile(new Appearance(name, skin), Language.fromCode(locale), randomSkin, favorites);
final NickoProfile profile = new NickoProfile(new Appearance(name, skin), Language.fromCode(locale), randomSkin, Collections.emptyList());
return Optional.of(profile);
} catch (SQLException e) {
logger.warning("Couldn't fetch profile: " + e.getMessage());
@ -127,14 +120,13 @@ public class MariaDBStorage extends Storage {
}
private PreparedStatement getInsertStatement(Connection connection, UUID uuid, NickoProfile profile) throws SQLException {
final String sql = "INSERT IGNORE INTO nicko.DATA (`uuid`, `name`, `skin`, `locale`, `randomskin`, `favorites`) VALUES (?, ?, ?, ?, ?, ?)";
final String sql = "INSERT IGNORE INTO nicko.DATA (`uuid`, `name`, `skin`, `locale`, `randomskin`) VALUES (?, ?, ?, ?, ?)";
final PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, uuid.toString());
statement.setString(2, profile.getName() == null ? null : profile.getName());
statement.setString(3, profile.getSkin() == null ? null : profile.getSkin());
statement.setString(4, profile.getLocale().getCode());
statement.setBoolean(5, profile.isRandomSkin());
statement.setString(6, gson.toJson(profile.getFavorites(), new TypeToken<List<Appearance>>() { }.getRawType()));
return statement;
}

View file

@ -1,8 +1,5 @@
package xyz.ineanto.nicko.storage.mysql;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import xyz.ineanto.nicko.appearance.ActionResult;
import xyz.ineanto.nicko.appearance.Appearance;
import xyz.ineanto.nicko.config.Configuration;
@ -15,7 +12,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.logging.Logger;
@ -23,7 +19,6 @@ import java.util.logging.Logger;
public class MySQLStorage extends Storage {
private final Logger logger = Logger.getLogger("SQLStorage");
private final Configuration configuration;
private final Gson gson = new GsonBuilder().serializeNulls().create();
private MySQLStorageProvider provider;
@ -91,16 +86,15 @@ public class MySQLStorage extends Storage {
String skin = "";
String locale = "";
boolean randomSkin = false;
List<Appearance> favorites = Collections.emptyList();
while (resultSet.next()) {
name = resultSet.getString("name");
skin = resultSet.getString("skin");
locale = resultSet.getString("locale");
randomSkin = resultSet.getBoolean("randomskin");
favorites = gson.fromJson(resultSet.getString("favorites"), new TypeToken<List<Appearance>>() { }.getType());
}
final NickoProfile profile = new NickoProfile(new Appearance(name, skin), Language.fromCode(locale), randomSkin, favorites);
// TODO (Ineanto, 17/05/2025): Retrieve favorites
final NickoProfile profile = new NickoProfile(new Appearance(name, skin), Language.fromCode(locale), randomSkin, Collections.emptyList());
return Optional.of(profile);
} catch (SQLException e) {
logger.warning("Couldn't fetch profile: " + e.getMessage());
@ -126,16 +120,13 @@ public class MySQLStorage extends Storage {
}
private PreparedStatement getInsertStatement(Connection connection, UUID uuid, NickoProfile profile) throws SQLException {
final String sql = "INSERT IGNORE INTO nicko.DATA (`uuid`, `name`, `skin`, `locale`, `randomskin`, `favorites`) VALUES (?, ?, ?, ?, ?, ?)";
final String sql = "INSERT IGNORE INTO nicko.DATA (`uuid`, `name`, `skin`, `locale`, `randomskin`) VALUES (?, ?, ?, ?, ?)";
final PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, uuid.toString());
statement.setString(2, profile.getName() == null ? null : profile.getName());
statement.setString(3, profile.getSkin() == null ? null : profile.getSkin());
statement.setString(4, profile.getLocale().getCode());
statement.setBoolean(5, profile.isRandomSkin());
// Ineanto, 08/06/2025: this will never fucking work
statement.setString(6, gson.toJson(profile.getFavorites(), new TypeToken<List<Appearance>>() { }.getRawType()));
return statement;
}