- Added per-world Block Damage settings - Added per-world Entity Damage settings - Added creeper_settings database support - Added world-specific Creeper menus - Added automatic world registration/default inheritance - Split Creeper listeners - Updated Creeper behavior to use world settings - Removed obsolete global Creeper indicators - Adopted logger-based error reporting standard
142 lines
3.4 KiB
Java
142 lines
3.4 KiB
Java
package com.rsscripting.serveradmin.dao;
|
|
|
|
import com.rsscripting.serveradmin.database.DatabaseManager;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
|
|
public class KeepInventoryDAO {
|
|
|
|
private final DatabaseManager databaseManager;
|
|
|
|
public KeepInventoryDAO(
|
|
DatabaseManager databaseManager
|
|
) {
|
|
|
|
this.databaseManager = databaseManager;
|
|
|
|
}
|
|
|
|
public boolean getWorldSetting(
|
|
String worldName
|
|
) throws SQLException {
|
|
|
|
Connection connection =
|
|
databaseManager.getConnection();
|
|
|
|
try (PreparedStatement statement =
|
|
connection.prepareStatement(
|
|
"""
|
|
SELECT enabled
|
|
FROM keep_inventory
|
|
WHERE world_name = ?
|
|
"""
|
|
)) {
|
|
|
|
statement.setString(
|
|
1,
|
|
worldName
|
|
);
|
|
|
|
try (ResultSet rs =
|
|
statement.executeQuery()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
return rs.getInt(
|
|
"enabled"
|
|
) == 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public void setWorldSetting(
|
|
String worldName,
|
|
boolean enabled
|
|
) throws SQLException {
|
|
|
|
Connection connection =
|
|
databaseManager.getConnection();
|
|
|
|
try (PreparedStatement statement =
|
|
connection.prepareStatement(
|
|
"""
|
|
INSERT OR REPLACE INTO keep_inventory
|
|
(
|
|
world_name,
|
|
enabled
|
|
)
|
|
VALUES
|
|
(
|
|
?,
|
|
?
|
|
)
|
|
"""
|
|
)) {
|
|
|
|
statement.setString(
|
|
1,
|
|
worldName
|
|
);
|
|
|
|
statement.setInt(
|
|
2,
|
|
enabled ? 1 : 0
|
|
);
|
|
|
|
statement.executeUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void ensureWorldExists(
|
|
String worldName,
|
|
boolean defaultValue
|
|
) throws SQLException {
|
|
|
|
Connection connection =
|
|
databaseManager.getConnection();
|
|
|
|
try (PreparedStatement statement =
|
|
connection.prepareStatement(
|
|
"""
|
|
INSERT OR IGNORE INTO keep_inventory
|
|
(
|
|
world_name,
|
|
enabled
|
|
)
|
|
VALUES
|
|
(
|
|
?,
|
|
?
|
|
)
|
|
"""
|
|
)) {
|
|
|
|
statement.setString(
|
|
1,
|
|
worldName
|
|
);
|
|
|
|
statement.setInt(
|
|
2,
|
|
defaultValue ? 1 : 0
|
|
);
|
|
|
|
statement.executeUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |