2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.rooms ;
import com.eu.habbo.Emulator ;
import java.sql.Connection ;
import java.sql.PreparedStatement ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
2019-05-26 20:14:53 +02:00
public class RoomBan {
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final int roomId ;
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final int userId ;
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final String username ;
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final int endTimestamp ;
2019-05-26 20:14:53 +02:00
public RoomBan ( int roomId , int userId , String username , int endTimestamp ) {
2018-07-06 15:30:00 +02:00
this . roomId = roomId ;
this . userId = userId ;
this . username = username ;
this . endTimestamp = endTimestamp ;
}
2019-05-26 20:14:53 +02:00
public RoomBan ( ResultSet set ) throws SQLException {
2018-07-06 15:30:00 +02:00
this . roomId = set . getInt ( " room_id " ) ;
this . userId = set . getInt ( " user_id " ) ;
this . username = set . getString ( " username " ) ;
this . endTimestamp = set . getInt ( " ends " ) ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void insert ( ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO room_bans (room_id, user_id, ends) VALUES (?, ?, ?) " ) ) {
2018-07-06 15:30:00 +02:00
statement . setInt ( 1 , this . roomId ) ;
statement . setInt ( 2 , this . userId ) ;
statement . setInt ( 3 , this . endTimestamp ) ;
statement . execute ( ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2018-07-06 15:30:00 +02:00
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void delete ( ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " DELETE FROM room_bans WHERE room_id = ? AND user_id = ? " ) ) {
2018-07-06 15:30:00 +02:00
statement . setInt ( 1 , this . roomId ) ;
statement . setInt ( 2 , this . userId ) ;
statement . execute ( ) ;
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2018-07-06 15:30:00 +02:00
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
}