2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.users ;
import com.eu.habbo.Emulator ;
import com.eu.habbo.habbohotel.achievements.Achievement ;
2018-11-17 14:28:00 +01:00
import com.eu.habbo.habbohotel.achievements.AchievementManager ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.achievements.TalentTrackType ;
import com.eu.habbo.habbohotel.catalog.CatalogItem ;
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles ;
2018-10-07 00:28:00 +02:00
import com.eu.habbo.habbohotel.rooms.RoomTrade ;
import com.eu.habbo.habbohotel.users.cache.HabboOfferPurchase ;
2018-07-06 15:30:00 +02:00
import gnu.trove.list.array.TIntArrayList ;
2018-10-07 00:28:00 +02:00
import gnu.trove.map.TIntObjectMap ;
2018-07-06 15:30:00 +02:00
import gnu.trove.map.hash.THashMap ;
2018-10-07 00:28:00 +02:00
import gnu.trove.map.hash.TIntObjectHashMap ;
2018-07-06 15:30:00 +02:00
import gnu.trove.stack.array.TIntArrayStack ;
import java.sql.Connection ;
import java.sql.PreparedStatement ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.List ;
2018-09-12 18:45:00 +02:00
import java.util.Map ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class HabboStats implements Runnable {
public final TIntArrayList secretRecipes ;
public final HabboNavigatorWindowSettings navigatorWindowSettings ;
public final THashMap < String , Object > cache ;
public final TIntArrayList calendarRewardsClaimed ;
public final TIntObjectMap < HabboOfferPurchase > offerCache = new TIntObjectHashMap < > ( ) ;
2018-07-06 15:30:00 +02:00
private final int timeLoggedIn = Emulator . getIntUnixTimestamp ( ) ;
2019-05-26 20:14:53 +02:00
private final THashMap < Achievement , Integer > achievementProgress ;
private final THashMap < Achievement , Integer > achievementCache ;
private final THashMap < Integer , CatalogItem > recentPurchases ;
private final TIntArrayList favoriteRooms ;
private final TIntArrayList ignoredUsers ;
2018-07-06 15:30:00 +02:00
public int achievementScore ;
public int respectPointsReceived ;
public int respectPointsGiven ;
public int respectPointsToGive ;
public int petRespectPointsToGive ;
public boolean blockFollowing ;
public boolean blockFriendRequests ;
public boolean blockRoomInvites ;
public boolean blockStaffAlerts ;
public boolean preferOldChat ;
public boolean blockCameraFollow ;
public RoomChatMessageBubbles chatColor ;
public int volumeSystem ;
public int volumeFurni ;
public int volumeTrax ;
public int guild ;
public List < Integer > guilds ;
public String [ ] tags ;
public TIntArrayStack votedRooms ;
public int loginStreak ;
public int rentedItemId ;
public int rentedTimeEnd ;
public int hofPoints ;
public boolean ignorePets ;
public boolean ignoreBots ;
2019-03-18 02:22:00 +01:00
public int citizenshipLevel ;
public int helpersLevel ;
public boolean perkTrade ;
2018-07-06 15:30:00 +02:00
public long roomEnterTimestamp ;
public int chatCounter ;
public long lastChat ;
public long lastUsersSearched ;
2019-03-18 02:22:00 +01:00
public boolean nux ;
public boolean nuxReward ;
2018-07-06 15:30:00 +02:00
public int nuxStep = 1 ;
public int mutedCount = 0 ;
public boolean mutedBubbleTracker = false ;
public String changeNameChecked = " " ;
2019-03-18 02:22:00 +01:00
public boolean allowNameChange ;
2018-10-07 00:28:00 +02:00
public boolean isPurchasingFurniture = false ;
2019-05-11 00:45:07 +02:00
public int forumPostsCount ;
2018-09-12 18:45:00 +02:00
public THashMap < Integer , List < Integer > > ltdPurchaseLog = new THashMap < > ( 0 ) ;
2018-10-07 00:28:00 +02:00
public long lastTradeTimestamp = Emulator . getIntUnixTimestamp ( ) ;
2020-04-28 01:16:56 +02:00
public int lastPurchaseTimestamp ;
2018-10-07 00:28:00 +02:00
public long lastGiftTimestamp = Emulator . getIntUnixTimestamp ( ) ;
2019-05-27 21:55:23 +02:00
public int uiFlags ;
2019-05-30 18:18:48 +02:00
public boolean hasGottenDefaultSavedSearches ;
2019-05-26 20:14:53 +02:00
private HabboInfo habboInfo ;
private boolean allowTrade ;
private int clubExpireTimestamp ;
private int muteEndTime ;
2018-09-12 18:45:00 +02:00
2019-05-26 20:14:53 +02:00
private HabboStats ( ResultSet set , HabboInfo habboInfo ) throws SQLException {
2018-09-28 21:25:00 +02:00
this . cache = new THashMap < > ( 0 ) ;
this . achievementProgress = new THashMap < > ( 0 ) ;
this . achievementCache = new THashMap < > ( 0 ) ;
this . recentPurchases = new THashMap < > ( 0 ) ;
2018-07-06 15:30:00 +02:00
this . favoriteRooms = new TIntArrayList ( 0 ) ;
this . ignoredUsers = new TIntArrayList ( 0 ) ;
this . secretRecipes = new TIntArrayList ( 0 ) ;
this . calendarRewardsClaimed = new TIntArrayList ( 0 ) ;
2019-05-11 00:45:07 +02:00
this . habboInfo = habboInfo ;
2018-07-06 15:30:00 +02:00
this . achievementScore = set . getInt ( " achievement_score " ) ;
this . respectPointsReceived = set . getInt ( " respects_received " ) ;
this . respectPointsGiven = set . getInt ( " respects_given " ) ;
this . petRespectPointsToGive = set . getInt ( " daily_pet_respect_points " ) ;
this . respectPointsToGive = set . getInt ( " daily_respect_points " ) ;
this . blockFollowing = set . getString ( " block_following " ) . equals ( " 1 " ) ;
this . blockFriendRequests = set . getString ( " block_friendrequests " ) . equals ( " 1 " ) ;
this . blockRoomInvites = set . getString ( " block_roominvites " ) . equals ( " 1 " ) ;
this . preferOldChat = set . getString ( " old_chat " ) . equals ( " 1 " ) ;
this . blockCameraFollow = set . getString ( " block_camera_follow " ) . equals ( " 1 " ) ;
this . guild = set . getInt ( " guild_id " ) ;
this . guilds = new ArrayList < > ( ) ;
this . tags = set . getString ( " tags " ) . split ( " ; " ) ;
this . allowTrade = set . getString ( " can_trade " ) . equals ( " 1 " ) ;
this . votedRooms = new TIntArrayStack ( ) ;
this . clubExpireTimestamp = set . getInt ( " club_expire_timestamp " ) ;
this . loginStreak = set . getInt ( " login_streak " ) ;
this . rentedItemId = set . getInt ( " rent_space_id " ) ;
this . rentedTimeEnd = set . getInt ( " rent_space_endtime " ) ;
this . volumeSystem = set . getInt ( " volume_system " ) ;
this . volumeFurni = set . getInt ( " volume_furni " ) ;
this . volumeTrax = set . getInt ( " volume_trax " ) ;
this . chatColor = RoomChatMessageBubbles . getBubble ( set . getInt ( " chat_color " ) ) ;
this . hofPoints = set . getInt ( " hof_points " ) ;
this . blockStaffAlerts = set . getString ( " block_alerts " ) . equals ( " 1 " ) ;
this . citizenshipLevel = set . getInt ( " talent_track_citizenship_level " ) ;
this . helpersLevel = set . getInt ( " talent_track_helpers_level " ) ;
this . ignoreBots = set . getString ( " ignore_bots " ) . equalsIgnoreCase ( " 1 " ) ;
this . ignorePets = set . getString ( " ignore_pets " ) . equalsIgnoreCase ( " 1 " ) ;
this . nux = set . getString ( " nux " ) . equals ( " 1 " ) ;
this . muteEndTime = set . getInt ( " mute_end_timestamp " ) ;
this . allowNameChange = set . getString ( " allow_name_change " ) . equalsIgnoreCase ( " 1 " ) ;
2018-10-07 00:28:00 +02:00
this . perkTrade = set . getString ( " perk_trade " ) . equalsIgnoreCase ( " 1 " ) ;
2019-05-11 00:45:07 +02:00
this . forumPostsCount = set . getInt ( " forums_post_count " ) ;
2019-05-27 21:55:23 +02:00
this . uiFlags = set . getInt ( " ui_flags " ) ;
2019-05-30 18:18:48 +02:00
this . hasGottenDefaultSavedSearches = set . getInt ( " has_gotten_default_saved_searches " ) = = 1 ;
2020-04-28 01:16:56 +02:00
this . lastPurchaseTimestamp = set . getInt ( " last_purchase_timestamp " ) ;
2019-03-18 02:22:00 +01:00
this . nuxReward = this . nux ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
try ( PreparedStatement statement = set . getStatement ( ) . getConnection ( ) . prepareStatement ( " SELECT * FROM user_window_settings WHERE user_id = ? LIMIT 1 " ) ) {
2019-05-11 00:45:07 +02:00
statement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet nSet = statement . executeQuery ( ) ) {
if ( nSet . next ( ) ) {
2018-07-06 15:30:00 +02:00
this . navigatorWindowSettings = new HabboNavigatorWindowSettings ( nSet ) ;
2019-05-26 20:14:53 +02:00
} else {
try ( PreparedStatement stmt = statement . getConnection ( ) . prepareStatement ( " INSERT INTO user_window_settings (user_id) VALUES (?) " ) ) {
2019-05-11 00:45:07 +02:00
stmt . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
stmt . executeUpdate ( ) ;
}
2019-05-11 00:45:07 +02:00
this . navigatorWindowSettings = new HabboNavigatorWindowSettings ( habboInfo . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
}
}
}
2019-05-26 20:14:53 +02:00
try ( PreparedStatement statement = set . getStatement ( ) . getConnection ( ) . prepareStatement ( " SELECT * FROM users_navigator_settings WHERE user_id = ? " ) ) {
2019-05-11 00:45:07 +02:00
statement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet nSet = statement . executeQuery ( ) ) {
while ( nSet . next ( ) ) {
2018-07-06 15:30:00 +02:00
this . navigatorWindowSettings . addDisplayMode ( nSet . getString ( " caption " ) , new HabboNavigatorPersonalDisplayMode ( nSet ) ) ;
}
}
}
2019-05-26 20:14:53 +02:00
try ( PreparedStatement favoriteRoomsStatement = set . getStatement ( ) . getConnection ( ) . prepareStatement ( " SELECT * FROM users_favorite_rooms WHERE user_id = ? " ) ) {
2019-05-11 00:45:07 +02:00
favoriteRoomsStatement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet favoriteSet = favoriteRoomsStatement . executeQuery ( ) ) {
while ( favoriteSet . next ( ) ) {
2018-07-06 15:30:00 +02:00
this . favoriteRooms . add ( favoriteSet . getInt ( " room_id " ) ) ;
}
}
}
2019-05-26 20:14:53 +02:00
try ( PreparedStatement recipesStatement = set . getStatement ( ) . getConnection ( ) . prepareStatement ( " SELECT * FROM users_recipes WHERE user_id = ? " ) ) {
2019-05-11 00:45:07 +02:00
recipesStatement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet recipeSet = recipesStatement . executeQuery ( ) ) {
while ( recipeSet . next ( ) ) {
2018-07-06 15:30:00 +02:00
this . secretRecipes . add ( recipeSet . getInt ( " recipe " ) ) ;
}
}
}
2019-05-26 20:14:53 +02:00
try ( PreparedStatement calendarRewardsStatement = set . getStatement ( ) . getConnection ( ) . prepareStatement ( " SELECT * FROM calendar_rewards_claimed WHERE user_id = ? " ) ) {
2019-05-11 00:45:07 +02:00
calendarRewardsStatement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet rewardSet = calendarRewardsStatement . executeQuery ( ) ) {
while ( rewardSet . next ( ) ) {
2018-07-06 15:30:00 +02:00
this . calendarRewardsClaimed . add ( rewardSet . getInt ( " reward_id " ) ) ;
}
}
}
2018-09-12 18:45:00 +02:00
2019-05-26 20:14:53 +02:00
try ( PreparedStatement ltdPurchaseLogStatement = set . getStatement ( ) . getConnection ( ) . prepareStatement ( " SELECT catalog_item_id, timestamp FROM catalog_items_limited WHERE user_id = ? AND timestamp > ? " ) ) {
2019-05-11 00:45:07 +02:00
ltdPurchaseLogStatement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2018-09-12 18:45:00 +02:00
ltdPurchaseLogStatement . setInt ( 2 , Emulator . getIntUnixTimestamp ( ) - 86400 ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet ltdSet = ltdPurchaseLogStatement . executeQuery ( ) ) {
while ( ltdSet . next ( ) ) {
2018-09-12 18:45:00 +02:00
this . addLtdLog ( ltdSet . getInt ( " catalog_item_id " ) , ltdSet . getInt ( " timestamp " ) ) ;
}
}
}
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
try ( PreparedStatement ignoredPlayersStatement = set . getStatement ( ) . getConnection ( ) . prepareStatement ( " SELECT target_id FROM users_ignored WHERE user_id = ? " ) ) {
2019-05-11 00:45:07 +02:00
ignoredPlayersStatement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet ignoredSet = ignoredPlayersStatement . executeQuery ( ) ) {
while ( ignoredSet . next ( ) ) {
2018-10-07 00:28:00 +02:00
this . ignoredUsers . add ( ignoredSet . getInt ( 1 ) ) ;
}
}
}
2019-05-26 20:14:53 +02:00
try ( PreparedStatement loadOfferPurchaseStatement = set . getStatement ( ) . getConnection ( ) . prepareStatement ( " SELECT * FROM users_target_offer_purchases WHERE user_id = ? " ) ) {
2019-05-11 00:45:07 +02:00
loadOfferPurchaseStatement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet offerSet = loadOfferPurchaseStatement . executeQuery ( ) ) {
while ( offerSet . next ( ) ) {
2018-10-07 00:28:00 +02:00
this . offerCache . put ( offerSet . getInt ( " offer_id " ) , new HabboOfferPurchase ( offerSet ) ) ;
}
}
}
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
private static HabboStats createNewStats ( HabboInfo habboInfo ) {
habboInfo . firstVisit = true ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO users_settings (user_id) VALUES (?) " ) ) {
statement . setInt ( 1 , habboInfo . getId ( ) ) ;
statement . executeUpdate ( ) ;
} catch ( SQLException e ) {
2020-05-03 01:46:07 +02:00
logger . error ( " Caught SQL exception " , e ) ;
2019-05-26 20:14:53 +02:00
}
return load ( habboInfo ) ;
}
public static HabboStats load ( HabboInfo habboInfo ) {
HabboStats stats = null ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ) {
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT * FROM users_settings WHERE user_id = ? LIMIT 1 " ) ) {
statement . setInt ( 1 , habboInfo . getId ( ) ) ;
try ( ResultSet set = statement . executeQuery ( ) ) {
set . first ( ) ;
if ( set . getRow ( ) ! = 0 ) {
stats = new HabboStats ( set , habboInfo ) ;
} else {
stats = createNewStats ( habboInfo ) ;
}
}
}
if ( stats ! = null ) {
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT guild_id FROM guilds_members WHERE user_id = ? AND level_id < 3 LIMIT 100 " ) ) {
statement . setInt ( 1 , habboInfo . getId ( ) ) ;
try ( ResultSet set = statement . executeQuery ( ) ) {
int i = 0 ;
while ( set . next ( ) ) {
stats . guilds . add ( set . getInt ( " guild_id " ) ) ;
i + + ;
}
}
}
Collections . sort ( stats . guilds ) ;
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT room_id FROM room_votes WHERE user_id = ? " ) ) {
statement . setInt ( 1 , habboInfo . getId ( ) ) ;
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
stats . votedRooms . push ( set . getInt ( " room_id " ) ) ;
}
}
}
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT * FROM users_achievements WHERE user_id = ? " ) ) {
statement . setInt ( 1 , habboInfo . getId ( ) ) ;
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
Achievement achievement = Emulator . getGameEnvironment ( ) . getAchievementManager ( ) . getAchievement ( set . getString ( " achievement_name " ) ) ;
if ( achievement ! = null ) {
stats . achievementProgress . put ( achievement , set . getInt ( " progress " ) ) ;
}
}
}
}
}
} catch ( SQLException e ) {
2020-05-03 01:46:07 +02:00
logger . error ( " Caught SQL exception " , e ) ;
2019-05-26 20:14:53 +02:00
}
return stats ;
}
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void run ( ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ) {
2020-04-28 01:16:56 +02:00
try ( PreparedStatement statement = connection . prepareStatement ( " UPDATE users_settings SET achievement_score = ?, respects_received = ?, respects_given = ?, daily_respect_points = ?, block_following = ?, block_friendrequests = ?, online_time = online_time + ?, guild_id = ?, daily_pet_respect_points = ?, club_expire_timestamp = ?, login_streak = ?, rent_space_id = ?, rent_space_endtime = ?, volume_system = ?, volume_furni = ?, volume_trax = ?, block_roominvites = ?, old_chat = ?, block_camera_follow = ?, chat_color = ?, hof_points = ?, block_alerts = ?, talent_track_citizenship_level = ?, talent_track_helpers_level = ?, ignore_bots = ?, ignore_pets = ?, nux = ?, mute_end_timestamp = ?, allow_name_change = ?, perk_trade = ?, can_trade = ?, `forums_post_count` = ?, ui_flags = ?, has_gotten_default_saved_searches = ?, last_purchase_timestamp = ? WHERE user_id = ? LIMIT 1 " ) ) {
2018-07-06 15:30:00 +02:00
statement . setInt ( 1 , this . achievementScore ) ;
statement . setInt ( 2 , this . respectPointsReceived ) ;
statement . setInt ( 3 , this . respectPointsGiven ) ;
statement . setInt ( 4 , this . respectPointsToGive ) ;
statement . setString ( 5 , this . blockFollowing ? " 1 " : " 0 " ) ;
statement . setString ( 6 , this . blockFriendRequests ? " 1 " : " 0 " ) ;
statement . setInt ( 7 , Emulator . getIntUnixTimestamp ( ) - this . timeLoggedIn ) ;
statement . setInt ( 8 , this . guild ) ;
statement . setInt ( 9 , this . petRespectPointsToGive ) ;
statement . setInt ( 10 , this . clubExpireTimestamp ) ;
statement . setInt ( 11 , this . loginStreak ) ;
statement . setInt ( 12 , this . rentedItemId ) ;
statement . setInt ( 13 , this . rentedTimeEnd ) ;
statement . setInt ( 14 , this . volumeSystem ) ;
statement . setInt ( 15 , this . volumeFurni ) ;
statement . setInt ( 16 , this . volumeTrax ) ;
statement . setString ( 17 , this . blockRoomInvites ? " 1 " : " 0 " ) ;
statement . setString ( 18 , this . preferOldChat ? " 1 " : " 0 " ) ;
statement . setString ( 19 , this . blockCameraFollow ? " 1 " : " 0 " ) ;
statement . setInt ( 20 , this . chatColor . getType ( ) ) ;
statement . setInt ( 21 , this . hofPoints ) ;
statement . setString ( 22 , this . blockStaffAlerts ? " 1 " : " 0 " ) ;
statement . setInt ( 23 , this . citizenshipLevel ) ;
statement . setInt ( 24 , this . helpersLevel ) ;
statement . setString ( 25 , this . ignoreBots ? " 1 " : " 0 " ) ;
statement . setString ( 26 , this . ignorePets ? " 1 " : " 0 " ) ;
statement . setString ( 27 , this . nux ? " 1 " : " 0 " ) ;
statement . setInt ( 28 , this . muteEndTime ) ;
statement . setString ( 29 , this . allowNameChange ? " 1 " : " 0 " ) ;
2018-10-07 00:28:00 +02:00
statement . setString ( 30 , this . perkTrade ? " 1 " : " 0 " ) ;
2018-11-17 14:28:00 +01:00
statement . setString ( 31 , this . allowTrade ? " 1 " : " 0 " ) ;
2019-05-11 00:45:07 +02:00
statement . setInt ( 32 , this . forumPostsCount ) ;
2019-05-27 21:55:23 +02:00
statement . setInt ( 33 , this . uiFlags ) ;
2019-05-30 18:18:48 +02:00
statement . setInt ( 34 , this . hasGottenDefaultSavedSearches ? 1 : 0 ) ;
2020-04-28 01:16:56 +02:00
statement . setInt ( 35 , this . lastPurchaseTimestamp ) ;
2019-05-27 22:17:54 +02:00
2020-04-28 01:16:56 +02:00
statement . setInt ( 36 , this . habboInfo . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
statement . executeUpdate ( ) ;
}
2019-05-26 20:14:53 +02:00
try ( PreparedStatement statement = connection . prepareStatement ( " UPDATE user_window_settings SET x = ?, y = ?, width = ?, height = ?, open_searches = ? WHERE user_id = ? LIMIT 1 " ) ) {
2018-07-06 15:30:00 +02:00
statement . setInt ( 1 , this . navigatorWindowSettings . x ) ;
statement . setInt ( 2 , this . navigatorWindowSettings . y ) ;
statement . setInt ( 3 , this . navigatorWindowSettings . width ) ;
statement . setInt ( 4 , this . navigatorWindowSettings . height ) ;
statement . setString ( 5 , this . navigatorWindowSettings . openSearches ? " 1 " : " 0 " ) ;
2019-05-11 00:45:07 +02:00
statement . setInt ( 6 , this . habboInfo . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
statement . executeUpdate ( ) ;
}
2019-05-26 20:14:53 +02:00
if ( ! this . offerCache . isEmpty ( ) ) {
try ( PreparedStatement statement = connection . prepareStatement ( " UPDATE users_target_offer_purchases SET state = ?, amount = ?, last_purchase = ? WHERE user_id = ? AND offer_id = ? " ) ) {
for ( HabboOfferPurchase purchase : this . offerCache . valueCollection ( ) ) {
2018-10-07 00:28:00 +02:00
if ( ! purchase . needsUpdate ( ) ) continue ;
statement . setInt ( 1 , purchase . getState ( ) ) ;
statement . setInt ( 2 , purchase . getAmount ( ) ) ;
statement . setInt ( 3 , purchase . getLastPurchaseTimestamp ( ) ) ;
2019-05-11 00:45:07 +02:00
statement . setInt ( 4 , this . habboInfo . getId ( ) ) ;
2018-10-07 00:28:00 +02:00
statement . setInt ( 5 , purchase . getOfferId ( ) ) ;
statement . execute ( ) ;
}
}
}
2018-07-06 15:30:00 +02:00
this . navigatorWindowSettings . save ( connection ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2020-05-03 01:46:07 +02:00
logger . error ( " Caught SQL exception " , e ) ;
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
public void dispose ( ) {
2018-07-06 15:30:00 +02:00
this . run ( ) ;
2019-05-11 00:45:07 +02:00
this . habboInfo = null ;
2018-07-06 15:30:00 +02:00
this . recentPurchases . clear ( ) ;
}
2019-05-26 20:14:53 +02:00
public void addGuild ( int guildId ) {
if ( ! this . guilds . contains ( guildId ) ) {
2018-07-06 15:30:00 +02:00
this . guilds . add ( guildId ) ;
}
}
2019-05-26 20:14:53 +02:00
public void removeGuild ( int guildId ) {
this . guilds . remove ( ( Integer ) guildId ) ;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public boolean hasGuild ( int guildId ) {
for ( int i : this . guilds ) {
if ( i = = guildId )
2018-07-06 15:30:00 +02:00
return true ;
}
return false ;
}
2019-05-26 20:14:53 +02:00
public int getAchievementScore ( ) {
2018-07-06 15:30:00 +02:00
return this . achievementScore ;
}
2019-05-26 20:14:53 +02:00
public void addAchievementScore ( int achievementScore ) {
2018-07-06 15:30:00 +02:00
this . achievementScore + = achievementScore ;
}
2019-05-26 20:14:53 +02:00
public int getAchievementProgress ( Achievement achievement ) {
if ( this . achievementProgress . containsKey ( achievement ) )
2018-07-06 15:30:00 +02:00
return this . achievementProgress . get ( achievement ) ;
return - 1 ;
}
2019-05-26 20:14:53 +02:00
public void setProgress ( Achievement achievement , int progress ) {
2018-07-06 15:30:00 +02:00
this . achievementProgress . put ( achievement , progress ) ;
}
2019-05-26 20:14:53 +02:00
public int getRentedTimeEnd ( ) {
2018-07-06 15:30:00 +02:00
return this . rentedTimeEnd ;
}
2019-05-26 20:14:53 +02:00
public void setRentedTimeEnd ( int rentedTimeEnd ) {
2018-07-06 15:30:00 +02:00
this . rentedTimeEnd = rentedTimeEnd ;
}
2019-05-26 20:14:53 +02:00
public int getRentedItemId ( ) {
2018-07-06 15:30:00 +02:00
return this . rentedItemId ;
}
2019-05-26 20:14:53 +02:00
public void setRentedItemId ( int rentedItemId ) {
2018-07-06 15:30:00 +02:00
this . rentedItemId = rentedItemId ;
}
2019-05-26 20:14:53 +02:00
public boolean isRentingSpace ( ) {
2019-03-18 02:22:00 +01:00
return this . rentedTimeEnd > = Emulator . getIntUnixTimestamp ( ) ;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public int getClubExpireTimestamp ( ) {
2018-07-06 15:30:00 +02:00
return this . clubExpireTimestamp ;
}
2019-05-26 20:14:53 +02:00
public void setClubExpireTimestamp ( int clubExpireTimestamp ) {
2018-07-06 15:30:00 +02:00
this . clubExpireTimestamp = clubExpireTimestamp ;
}
2019-05-26 20:14:53 +02:00
public boolean hasActiveClub ( ) {
2018-07-06 15:30:00 +02:00
return this . clubExpireTimestamp > Emulator . getIntUnixTimestamp ( ) ;
}
2019-05-26 20:14:53 +02:00
public THashMap < Achievement , Integer > getAchievementProgress ( ) {
2018-07-06 15:30:00 +02:00
return this . achievementProgress ;
}
2019-05-26 20:14:53 +02:00
public THashMap < Achievement , Integer > getAchievementCache ( ) {
2018-07-06 15:30:00 +02:00
return this . achievementCache ;
}
2019-05-26 20:14:53 +02:00
public void addPurchase ( CatalogItem item ) {
if ( ! this . recentPurchases . containsKey ( item . getId ( ) ) ) {
2018-07-06 15:30:00 +02:00
this . recentPurchases . put ( item . getId ( ) , item ) ;
}
}
2019-05-26 20:14:53 +02:00
public THashMap < Integer , CatalogItem > getRecentPurchases ( ) {
2018-07-06 15:30:00 +02:00
return this . recentPurchases ;
}
2019-05-26 20:14:53 +02:00
public void disposeRecentPurchases ( ) {
2018-07-06 15:30:00 +02:00
this . recentPurchases . clear ( ) ;
}
2019-05-26 20:14:53 +02:00
public boolean addFavoriteRoom ( int roomId ) {
2018-07-06 15:30:00 +02:00
if ( this . favoriteRooms . contains ( roomId ) )
return false ;
if ( Emulator . getConfig ( ) . getInt ( " hotel.rooms.max.favorite " ) < = this . favoriteRooms . size ( ) )
return false ;
2019-05-26 20:14:53 +02:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO users_favorite_rooms (user_id, room_id) VALUES (?, ?) " ) ) {
2019-05-11 00:45:07 +02:00
statement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
statement . setInt ( 2 , roomId ) ;
statement . execute ( ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2020-05-03 01:46:07 +02:00
logger . error ( " Caught SQL exception " , e ) ;
2018-07-06 15:30:00 +02:00
}
this . favoriteRooms . add ( roomId ) ;
return true ;
}
2019-05-26 20:14:53 +02:00
public void removeFavoriteRoom ( int roomId ) {
if ( this . favoriteRooms . remove ( roomId ) ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " DELETE FROM users_favorite_rooms WHERE user_id = ? AND room_id = ? LIMIT 1 " ) ) {
2019-05-11 00:45:07 +02:00
statement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
statement . setInt ( 2 , roomId ) ;
statement . execute ( ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2020-05-03 01:46:07 +02:00
logger . error ( " Caught SQL exception " , e ) ;
2018-07-06 15:30:00 +02:00
}
}
}
2019-05-26 20:14:53 +02:00
public boolean hasFavoriteRoom ( int roomId ) {
2018-07-06 15:30:00 +02:00
return this . favoriteRooms . contains ( roomId ) ;
}
2019-05-26 20:14:53 +02:00
public TIntArrayList getFavoriteRooms ( ) {
2018-07-06 15:30:00 +02:00
return this . favoriteRooms ;
}
2019-05-26 20:14:53 +02:00
public boolean hasRecipe ( int id ) {
2018-07-06 15:30:00 +02:00
return this . secretRecipes . contains ( id ) ;
}
2019-05-26 20:14:53 +02:00
public boolean addRecipe ( int id ) {
2018-07-06 15:30:00 +02:00
if ( this . secretRecipes . contains ( id ) )
return false ;
2019-05-26 20:14:53 +02:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO users_recipes (user_id, recipe) VALUES (?, ?) " ) ) {
2019-05-11 00:45:07 +02:00
statement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
statement . setInt ( 2 , id ) ;
statement . execute ( ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2020-05-03 01:46:07 +02:00
logger . error ( " Caught SQL exception " , e ) ;
2018-07-06 15:30:00 +02:00
}
this . secretRecipes . add ( id ) ;
return true ;
}
2019-05-26 20:14:53 +02:00
public int talentTrackLevel ( TalentTrackType type ) {
2018-07-06 15:30:00 +02:00
if ( type = = TalentTrackType . CITIZENSHIP )
return this . citizenshipLevel ;
else if ( type = = TalentTrackType . HELPER )
return this . helpersLevel ;
return - 1 ;
}
2019-05-26 20:14:53 +02:00
public void setTalentLevel ( TalentTrackType type , int level ) {
2018-07-06 15:30:00 +02:00
if ( type = = TalentTrackType . CITIZENSHIP )
this . citizenshipLevel = level ;
else if ( type = = TalentTrackType . HELPER )
this . helpersLevel = level ;
}
2019-05-26 20:14:53 +02:00
public int getMuteEndTime ( ) {
2018-07-06 15:30:00 +02:00
return this . muteEndTime ;
}
2019-05-26 20:14:53 +02:00
public int addMuteTime ( int seconds ) {
if ( this . remainingMuteTime ( ) = = 0 ) {
2018-07-06 15:30:00 +02:00
this . muteEndTime = Emulator . getIntUnixTimestamp ( ) ;
}
this . mutedBubbleTracker = true ;
this . muteEndTime + = seconds ;
2019-03-18 02:22:00 +01:00
return this . remainingMuteTime ( ) ;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public int remainingMuteTime ( ) {
2018-07-06 15:30:00 +02:00
return Math . max ( 0 , this . muteEndTime - Emulator . getIntUnixTimestamp ( ) ) ;
}
2019-05-26 20:14:53 +02:00
public boolean allowTalk ( ) {
2018-07-06 15:30:00 +02:00
return this . remainingMuteTime ( ) = = 0 ;
}
2019-05-26 20:14:53 +02:00
public void unMute ( ) {
2018-07-06 15:30:00 +02:00
this . muteEndTime = 0 ;
this . mutedBubbleTracker = false ;
}
2018-09-12 18:45:00 +02:00
2019-05-26 20:14:53 +02:00
public void addLtdLog ( int catalogItemId , int timestamp ) {
if ( ! this . ltdPurchaseLog . containsKey ( catalogItemId ) ) {
2018-09-12 18:45:00 +02:00
this . ltdPurchaseLog . put ( catalogItemId , new ArrayList < > ( 1 ) ) ;
}
this . ltdPurchaseLog . get ( catalogItemId ) . add ( timestamp ) ;
}
2019-05-26 20:14:53 +02:00
public int totalLtds ( ) {
2018-09-12 18:45:00 +02:00
int total = 0 ;
2019-05-26 20:14:53 +02:00
for ( Map . Entry < Integer , List < Integer > > entry : this . ltdPurchaseLog . entrySet ( ) ) {
2018-09-12 18:45:00 +02:00
total + = entry . getValue ( ) . size ( ) ;
}
return total ;
}
2019-05-26 20:14:53 +02:00
public int totalLtds ( int catalogItemId ) {
if ( this . ltdPurchaseLog . containsKey ( catalogItemId ) ) {
2018-09-12 18:45:00 +02:00
return this . ltdPurchaseLog . get ( catalogItemId ) . size ( ) ;
}
return 0 ;
}
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
public void ignoreUser ( int userId ) {
if ( ! this . userIgnored ( userId ) ) {
2018-10-07 00:28:00 +02:00
this . ignoredUsers . add ( userId ) ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ;
2019-05-26 20:14:53 +02:00
PreparedStatement statement = connection . prepareStatement ( " INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?) " ) ) {
2019-05-11 00:45:07 +02:00
statement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2018-10-07 00:28:00 +02:00
statement . setInt ( 2 , userId ) ;
statement . execute ( ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2020-05-03 01:46:07 +02:00
logger . error ( " Caught SQL exception " , e ) ;
2018-10-07 00:28:00 +02:00
}
}
}
2019-05-26 20:14:53 +02:00
public void unignoreUser ( int userId ) {
if ( this . userIgnored ( userId ) ) {
2018-10-07 00:28:00 +02:00
this . ignoredUsers . remove ( userId ) ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ;
2019-05-26 20:14:53 +02:00
PreparedStatement statement = connection . prepareStatement ( " DELETE FROM users_ignored WHERE user_id = ? AND target_id = ? " ) ) {
2019-05-11 00:45:07 +02:00
statement . setInt ( 1 , this . habboInfo . getId ( ) ) ;
2018-10-07 00:28:00 +02:00
statement . setInt ( 2 , userId ) ;
statement . execute ( ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2020-05-03 01:46:07 +02:00
logger . error ( " Caught SQL exception " , e ) ;
2018-10-07 00:28:00 +02:00
}
}
}
2019-05-26 20:14:53 +02:00
public boolean userIgnored ( int userId ) {
2018-10-07 00:28:00 +02:00
return this . ignoredUsers . contains ( userId ) ;
}
2019-05-26 20:14:53 +02:00
public boolean allowTrade ( ) {
2018-11-17 14:28:00 +01:00
if ( AchievementManager . TALENTTRACK_ENABLED & & RoomTrade . TRADING_REQUIRES_PERK )
2018-10-07 00:28:00 +02:00
return this . perkTrade & & this . allowTrade ;
else return this . allowTrade ;
}
2019-05-26 20:14:53 +02:00
public void setAllowTrade ( boolean allowTrade ) {
2018-10-07 00:28:00 +02:00
this . allowTrade = allowTrade ;
}
2019-05-26 20:14:53 +02:00
public HabboOfferPurchase getHabboOfferPurchase ( int offerId ) {
2018-10-07 00:28:00 +02:00
return this . offerCache . get ( offerId ) ;
}
2019-05-26 20:14:53 +02:00
public void addHabboOfferPurchase ( HabboOfferPurchase offerPurchase ) {
2018-10-07 00:28:00 +02:00
this . offerCache . put ( offerPurchase . getOfferId ( ) , offerPurchase ) ;
}
2018-07-06 15:30:00 +02:00
}