mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Start command refactor
This commit is contained in:
1 parent
39e0b25d46
commit
3e27f7c5b1
57 files changed
+728
-384
No files matched your search
@@ -3,7 +3,7 @@ package net.william278.huskhomes.database;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import net.william278.huskhomes.user.UserData;
|
||||
import net.william278.huskhomes.user.SavedUser;
|
||||
import net.william278.huskhomes.position.*;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.util.Logger;
|
||||
@@ -218,27 +218,27 @@ public abstract class Database {
|
||||
protected abstract void updateSavedPosition(int savedPositionId, @NotNull SavedPosition savedPosition, @NotNull Connection connection) throws SQLException;
|
||||
|
||||
/**
|
||||
* Ensure a {@link User} has a {@link UserData} entry in the database and that their username is up-to-date
|
||||
* Ensure a {@link User} has a {@link SavedUser} entry in the database and that their username is up-to-date
|
||||
*
|
||||
* @param user The {@link User} to ensure
|
||||
*/
|
||||
public abstract void ensureUser(@NotNull User user);
|
||||
|
||||
/**
|
||||
* Get {@link UserData} for a user by their Minecraft username (<i>case-insensitive</i>)
|
||||
* Get {@link SavedUser} for a user by their Minecraft username (<i>case-insensitive</i>)
|
||||
*
|
||||
* @param name Username of the {@link UserData} to get (<i>case-insensitive</i>)
|
||||
* @return A future returning an optional with the {@link UserData} present if they exist
|
||||
* @param name Username of the {@link SavedUser} to get (<i>case-insensitive</i>)
|
||||
* @return A future returning an optional with the {@link SavedUser} present if they exist
|
||||
*/
|
||||
public abstract Optional<UserData> getUserDataByName(@NotNull String name);
|
||||
public abstract Optional<SavedUser> getUserDataByName(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Get {@link UserData} for a user by their Minecraft account {@link UUID}
|
||||
* Get {@link SavedUser} for a user by their Minecraft account {@link UUID}
|
||||
*
|
||||
* @param uuid Minecraft account {@link UUID} of the {@link UserData} to get
|
||||
* @return A future returning an optional with the {@link UserData} present if they exist
|
||||
* @param uuid Minecraft account {@link UUID} of the {@link SavedUser} to get
|
||||
* @return A future returning an optional with the {@link SavedUser} present if they exist
|
||||
*/
|
||||
public abstract Optional<UserData> getUserData(@NotNull UUID uuid);
|
||||
public abstract Optional<SavedUser> getUserData(@NotNull UUID uuid);
|
||||
|
||||
|
||||
/**
|
||||
@@ -331,11 +331,11 @@ public abstract class Database {
|
||||
public abstract Optional<Teleport> getCurrentTeleport(@NotNull OnlineUser onlineUser);
|
||||
|
||||
/**
|
||||
* Updates a user in the database with new {@link UserData}
|
||||
* Updates a user in the database with new {@link SavedUser}
|
||||
*
|
||||
* @param userData The {@link UserData} to update
|
||||
* @param savedUser The {@link SavedUser} to update
|
||||
*/
|
||||
public abstract void updateUserData(@NotNull UserData userData);
|
||||
public abstract void updateUserData(@NotNull SavedUser savedUser);
|
||||
|
||||
/**
|
||||
* Sets or clears the current {@link Teleport} being executed by a {@link User}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.zaxxer.hikari.HikariDataSource;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import net.william278.huskhomes.user.UserData;
|
||||
import net.william278.huskhomes.user.SavedUser;
|
||||
import net.william278.huskhomes.position.*;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -278,7 +278,7 @@ public class MySqlDatabase extends Database {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UserData> getUserDataByName(@NotNull String name) {
|
||||
public Optional<SavedUser> getUserDataByName(@NotNull String name) {
|
||||
try (Connection connection = getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||
SELECT `uuid`, `username`, `home_slots`, `ignoring_requests`, `rtp_cooldown`
|
||||
@@ -288,7 +288,7 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new UserData(
|
||||
return Optional.of(new SavedUser(
|
||||
new User(UUID.fromString(resultSet.getString("uuid")),
|
||||
resultSet.getString("username")),
|
||||
resultSet.getInt("home_slots"),
|
||||
@@ -303,7 +303,7 @@ public class MySqlDatabase extends Database {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UserData> getUserData(@NotNull UUID uuid) {
|
||||
public Optional<SavedUser> getUserData(@NotNull UUID uuid) {
|
||||
try (Connection connection = getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||
SELECT `uuid`, `username`, `home_slots`, `ignoring_requests`, `rtp_cooldown`
|
||||
@@ -314,7 +314,7 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new UserData(
|
||||
return Optional.of(new SavedUser(
|
||||
new User(UUID.fromString(resultSet.getString("uuid")),
|
||||
resultSet.getString("username")),
|
||||
resultSet.getInt("home_slots"),
|
||||
@@ -622,21 +622,21 @@ public class MySqlDatabase extends Database {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserData(@NotNull UserData userData) {
|
||||
public void updateUserData(@NotNull SavedUser savedUser) {
|
||||
try (Connection connection = getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
|
||||
UPDATE `%players_table%`
|
||||
SET `home_slots`=?, `ignoring_requests`=?, `rtp_cooldown`=?
|
||||
WHERE `uuid`=?"""))) {
|
||||
|
||||
statement.setInt(1, userData.homeSlots());
|
||||
statement.setBoolean(2, userData.ignoringTeleports());
|
||||
statement.setTimestamp(3, Timestamp.from(userData.rtpCooldown()));
|
||||
statement.setString(4, userData.getUserUuid().toString());
|
||||
statement.setInt(1, savedUser.homeSlots());
|
||||
statement.setBoolean(2, savedUser.ignoringTeleports());
|
||||
statement.setTimestamp(3, Timestamp.from(savedUser.rtpCooldown()));
|
||||
statement.setString(4, savedUser.getUserUuid().toString());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
getLogger().log(Level.SEVERE, "Failed to update user data for " + userData.getUsername() + " on the database", e);
|
||||
getLogger().log(Level.SEVERE, "Failed to update user data for " + savedUser.getUsername() + " on the database", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.william278.huskhomes.database;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import net.william278.huskhomes.user.UserData;
|
||||
import net.william278.huskhomes.user.SavedUser;
|
||||
import net.william278.huskhomes.position.*;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -274,7 +274,7 @@ public class SqLiteDatabase extends Database {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UserData> getUserDataByName(@NotNull String name) {
|
||||
public Optional<SavedUser> getUserDataByName(@NotNull String name) {
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `uuid`, `username`, `home_slots`, `ignoring_requests`, `rtp_cooldown`
|
||||
@@ -284,7 +284,7 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new UserData(
|
||||
return Optional.of(new SavedUser(
|
||||
new User(UUID.fromString(resultSet.getString("uuid")),
|
||||
resultSet.getString("username")),
|
||||
resultSet.getInt("home_slots"),
|
||||
@@ -299,7 +299,7 @@ public class SqLiteDatabase extends Database {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UserData> getUserData(@NotNull UUID uuid) {
|
||||
public Optional<SavedUser> getUserData(@NotNull UUID uuid) {
|
||||
try {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
SELECT `uuid`, `username`, `home_slots`, `ignoring_requests`, `rtp_cooldown`
|
||||
@@ -310,7 +310,7 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new UserData(
|
||||
return Optional.of(new SavedUser(
|
||||
new User(UUID.fromString(resultSet.getString("uuid")),
|
||||
resultSet.getString("username")),
|
||||
resultSet.getInt("home_slots"),
|
||||
@@ -618,19 +618,19 @@ public class SqLiteDatabase extends Database {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserData(@NotNull UserData userData) {
|
||||
public void updateUserData(@NotNull SavedUser savedUser) {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(formatStatementTables("""
|
||||
UPDATE `%players_table%`
|
||||
SET `home_slots`=?, `ignoring_requests`=?, `rtp_cooldown`=?
|
||||
WHERE `uuid`=?"""))) {
|
||||
|
||||
statement.setInt(1, userData.homeSlots());
|
||||
statement.setBoolean(2, userData.ignoringTeleports());
|
||||
statement.setTimestamp(3, Timestamp.from(userData.rtpCooldown()));
|
||||
statement.setString(4, userData.getUserUuid().toString());
|
||||
statement.setInt(1, savedUser.homeSlots());
|
||||
statement.setBoolean(2, savedUser.ignoringTeleports());
|
||||
statement.setTimestamp(3, Timestamp.from(savedUser.rtpCooldown()));
|
||||
statement.setString(4, savedUser.getUserUuid().toString());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
getLogger().log(Level.SEVERE, "Failed to update user data for " + userData.getUsername() + " on the database", e);
|
||||
getLogger().log(Level.SEVERE, "Failed to update user data for " + savedUser.getUsername() + " on the database", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user