Backported some minor fixes from ms4, credits to brenoepic.

This commit is contained in:
Harmonic 2023-01-04 18:45:55 -08:00
parent 4340261506
commit f051d1d155
2 changed files with 3 additions and 8 deletions

View File

@ -27,7 +27,7 @@ public class AddYoutubePlaylistCommand extends Command {
int itemId; int itemId;
try { try {
itemId = Integer.valueOf(params[1]); itemId = Integer.parseInt(params[1]);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_add_youtube_playlist.no_base_item")); gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_add_youtube_playlist.no_base_item"));
return true; return true;
@ -45,7 +45,7 @@ public class AddYoutubePlaylistCommand extends Command {
return true; return true;
} }
Emulator.getGameEnvironment().getItemManager().getYoutubeManager().addPlaylistToItem(Integer.valueOf(params[1]), playlist); Emulator.getGameEnvironment().getItemManager().getYoutubeManager().addPlaylistToItem(Integer.parseInt(params[1]), playlist);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO `youtube_playlists` (`item_id`, `playlist_id`) VALUES (?, ?)")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO `youtube_playlists` (`item_id`, `playlist_id`) VALUES (?, ?)")) {
statement.setInt(1, itemId); statement.setInt(1, itemId);

View File

@ -95,20 +95,15 @@ public class YoutubeManager {
final String playlistId = set.getString("playlist_id"); final String playlistId = set.getString("playlist_id");
youtubeDataLoaderPool.submit(() -> { youtubeDataLoaderPool.submit(() -> {
ArrayList<YoutubePlaylist> playlists = this.playlists.getOrDefault(itemId, new ArrayList<>());
YoutubePlaylist playlist; YoutubePlaylist playlist;
try { try {
playlist = this.getPlaylistDataById(playlistId); playlist = this.getPlaylistDataById(playlistId);
if (playlist != null) { if (playlist != null) {
playlists.add(playlist); this.addPlaylistToItem(itemId, playlist);
} }
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Failed to load YouTube playlist {} ERROR: {}", playlistId, e); LOGGER.error("Failed to load YouTube playlist {} ERROR: {}", playlistId, e);
} }
this.playlists.put(itemId, playlists);
}); });
} }
} }