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

50 lines
1.6 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 CustomRoomLayout extends RoomLayout implements Runnable {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(CustomRoomLayout.class);
2018-12-22 11:39:00 +01:00
private final int roomId;
2019-05-26 20:14:53 +02:00
private boolean needsUpdate;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public CustomRoomLayout(ResultSet set, Room room) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, room);
2018-12-22 11:39:00 +01:00
this.roomId = room.getId();
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void run() {
if (this.needsUpdate) {
2018-07-06 15:30:00 +02:00
this.needsUpdate = false;
2019-05-26 20:14:53 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE room_models_custom SET door_x = ?, door_y = ?, door_dir = ?, heightmap = ? WHERE id = ? LIMIT 1")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, this.getDoorX());
statement.setInt(2, this.getDoorY());
statement.setInt(3, this.getDoorDirection());
statement.setString(4, this.getHeightmap());
2018-12-22 11:39:00 +01:00
statement.setInt(5, this.roomId);
2018-07-06 15:30:00 +02:00
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
}
}
}
2019-05-26 20:14:53 +02:00
public boolean needsUpdate() {
2018-07-06 15:30:00 +02:00
return this.needsUpdate;
}
2019-05-26 20:14:53 +02:00
public void needsUpdate(boolean needsUpdate) {
2018-07-06 15:30:00 +02:00
this.needsUpdate = needsUpdate;
}
}