Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/users/HabboNavigatorWindowSettings.java

124 lines
4.7 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.users;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.navigation.DisplayMode;
import com.eu.habbo.habbohotel.navigation.ListMode;
import gnu.trove.map.hash.THashMap;
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;
import java.util.Map;
2019-05-26 20:14:53 +02:00
public class HabboNavigatorWindowSettings {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(HabboNavigatorWindowSettings.class);
2019-05-26 20:14:53 +02:00
public final THashMap<String, HabboNavigatorPersonalDisplayMode> displayModes = new THashMap<>(2);
2018-07-06 15:30:00 +02:00
private final int userId;
public int x = 100;
public int y = 100;
public int width = 425;
public int height = 535;
public boolean openSearches = false;
public int unknown = 0;
2019-05-26 20:14:53 +02:00
public HabboNavigatorWindowSettings(int userId) {
2018-07-06 15:30:00 +02:00
this.userId = userId;
}
2019-05-26 20:14:53 +02:00
public HabboNavigatorWindowSettings(ResultSet set) throws SQLException {
2018-07-06 15:30:00 +02:00
this.userId = set.getInt("user_id");
this.x = set.getInt("x");
this.y = set.getInt("y");
this.width = set.getInt("width");
this.height = set.getInt("height");
this.openSearches = set.getBoolean("open_searches");
2018-07-06 15:30:00 +02:00
this.unknown = 0;
}
2019-05-26 20:14:53 +02:00
public void addDisplayMode(String category, HabboNavigatorPersonalDisplayMode displayMode) {
2018-07-06 15:30:00 +02:00
this.displayModes.put(category, displayMode);
}
2019-05-26 20:14:53 +02:00
public boolean hasDisplayMode(String category) {
2018-07-06 15:30:00 +02:00
return this.displayModes.containsKey(category);
}
2019-05-26 20:14:53 +02:00
public void insertDisplayMode(String category, ListMode listMode, DisplayMode displayMode) {
if (!this.displayModes.containsKey(category)) {
2018-07-06 15:30:00 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
2019-05-26 20:14:53 +02:00
PreparedStatement statement = connection.prepareStatement("INSERT INTO users_navigator_settings (user_id, caption, list_type, display) VALUES (?, ?, ?, ?)")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, this.userId);
statement.setString(2, category);
statement.setString(3, listMode.name().toLowerCase());
statement.setString(4, displayMode.name().toLowerCase());
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
}
this.displayModes.put(category, new HabboNavigatorPersonalDisplayMode(listMode, displayMode));
}
}
2019-05-26 20:14:53 +02:00
public void setDisplayMode(String category, DisplayMode displayMode) {
2018-07-06 15:30:00 +02:00
HabboNavigatorPersonalDisplayMode personalDisplayMode = this.displayModes.get(category);
2019-05-26 20:14:53 +02:00
if (personalDisplayMode != null) {
2018-07-06 15:30:00 +02:00
personalDisplayMode.displayMode = displayMode;
2019-05-26 20:14:53 +02:00
} else {
2019-03-18 02:22:00 +01:00
this.insertDisplayMode(category, ListMode.LIST, displayMode);
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
public void setListMode(String category, ListMode listMode) {
2018-07-06 15:30:00 +02:00
HabboNavigatorPersonalDisplayMode personalDisplayMode = this.displayModes.get(category);
2019-05-26 20:14:53 +02:00
if (personalDisplayMode != null) {
2018-07-06 15:30:00 +02:00
personalDisplayMode.listMode = listMode;
2019-05-26 20:14:53 +02:00
} else {
2019-03-18 02:22:00 +01:00
this.insertDisplayMode(category, listMode, DisplayMode.VISIBLE);
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
public DisplayMode getDisplayModeForCategory(String category) {
2018-07-06 15:30:00 +02:00
return this.getDisplayModeForCategory(category, DisplayMode.VISIBLE);
}
2019-05-26 20:14:53 +02:00
public DisplayMode getDisplayModeForCategory(String category, DisplayMode standard) {
if (this.displayModes.containsKey(category)) {
2018-07-06 15:30:00 +02:00
return this.displayModes.get(category).displayMode;
}
return standard;
}
2019-05-26 20:14:53 +02:00
public ListMode getListModeForCategory(String category) {
return this.getListModeForCategory(category, ListMode.LIST);
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public ListMode getListModeForCategory(String category, ListMode standard) {
if (this.displayModes.containsKey(category)) {
2018-07-06 15:30:00 +02:00
return this.displayModes.get(category).listMode;
}
return standard;
}
2019-05-26 20:14:53 +02:00
public void save(Connection connection) {
try (PreparedStatement statement = connection.prepareStatement("UPDATE users_navigator_settings SET list_type = ?, display = ? WHERE user_id = ? AND caption = ? LIMIT 1")) {
for (Map.Entry<String, HabboNavigatorPersonalDisplayMode> set : this.displayModes.entrySet()) {
2018-07-06 15:30:00 +02:00
statement.setString(1, set.getValue().listMode.name().toLowerCase());
statement.setString(2, set.getValue().displayMode.name().toLowerCase());
statement.setInt(3, this.userId);
statement.setString(4, set.getKey());
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
}
}
}