Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/rooms/RoomBan.java

58 lines
1.9 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
2020-05-04 22:24:09 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2018-07-06 15:30:00 +02:00
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
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(RoomBan.class);
2018-12-22 11:39:00 +01:00
2020-05-04 22:24:09 +02:00
public final int roomId;
2018-07-06 15:30:00 +02:00
public final int userId;
public final String username;
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) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught SQL exception", e);
2018-07-06 15:30:00 +02:00
}
}
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) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught SQL exception", e);
2018-07-06 15:30:00 +02:00
}
}
}