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

104 lines
2.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 RoomPromotion {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(RoomPromotion.class);
2018-07-06 15:30:00 +02:00
private final Room room;
2019-05-26 20:14:53 +02:00
public boolean needsUpdate;
2018-07-06 15:30:00 +02:00
private String title;
private String description;
private int endTimestamp;
2020-01-27 19:45:44 +01:00
private int startTimestamp;
private int category;
2018-07-06 15:30:00 +02:00
2020-01-27 19:45:44 +01:00
public RoomPromotion(Room room, String title, String description, int endTimestamp, int startTimestamp, int category) {
2018-07-06 15:30:00 +02:00
this.room = room;
this.title = title;
this.description = description;
this.endTimestamp = endTimestamp;
2020-01-27 19:45:44 +01:00
this.startTimestamp = startTimestamp;
this.category = category;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public RoomPromotion(Room room, ResultSet set) throws SQLException {
2018-07-06 15:30:00 +02:00
this.room = room;
this.title = set.getString("title");
this.description = set.getString("description");
this.endTimestamp = set.getInt("end_timestamp");
2020-01-27 19:45:44 +01:00
this.startTimestamp = set.getInt("start_timestamp");
this.category = set.getInt("category");
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void save() {
if (this.needsUpdate) {
2020-01-27 19:45:44 +01:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE room_promotions SET title = ?, description = ?, category = ? WHERE room_id = ?")) {
2018-07-06 15:30:00 +02:00
statement.setString(1, this.title);
statement.setString(2, this.description);
2020-01-27 19:45:44 +01:00
statement.setInt(3, this.category);
statement.setInt(4, this.room.getId());
2018-07-06 15:30:00 +02:00
statement.executeUpdate();
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
}
this.needsUpdate = false;
}
}
2019-05-26 20:14:53 +02:00
public Room getRoom() {
2018-07-06 15:30:00 +02:00
return this.room;
}
2019-05-26 20:14:53 +02:00
public String getTitle() {
2018-07-06 15:30:00 +02:00
return this.title;
}
2019-05-26 20:14:53 +02:00
public void setTitle(String title) {
2018-07-06 15:30:00 +02:00
this.title = title;
}
2019-05-26 20:14:53 +02:00
public String getDescription() {
2018-07-06 15:30:00 +02:00
return this.description;
}
2019-05-26 20:14:53 +02:00
public void setDescription(String description) {
2018-07-06 15:30:00 +02:00
this.description = description;
}
2019-05-26 20:14:53 +02:00
public int getEndTimestamp() {
2018-07-06 15:30:00 +02:00
return this.endTimestamp;
}
2019-05-26 20:14:53 +02:00
public void setEndTimestamp(int endTimestamp) {
2018-07-06 15:30:00 +02:00
this.endTimestamp = endTimestamp;
}
2019-05-26 20:14:53 +02:00
public void addEndTimestamp(int time) {
2018-07-06 15:30:00 +02:00
this.endTimestamp += time;
}
2020-01-27 19:45:44 +01:00
public int getStartTimestamp() {
return startTimestamp;
}
public void setStartTimestamp(int startTimestamp) {
this.startTimestamp = startTimestamp;
}
public int getCategory() {
return category;
}
public void setCategory(int category) {
this.category = category;
}
2018-07-06 15:30:00 +02:00
}