Skip to content

Commit

Permalink
Move class in API
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Dec 23, 2024
1 parent f8036f5 commit 1de5e52
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 132 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.euphyllia.skylliaore.database;

import fr.euphyllia.skyllia.configuration.ConfigToml;
import fr.euphyllia.skyllia.database.query.DatabaseInitializeQuery;
import fr.euphyllia.skyllia.api.database.DatabaseInitializeQuery;
import fr.euphyllia.skyllia.sgbd.DatabaseLoader;
import fr.euphyllia.skyllia.sgbd.MariaDB;
import fr.euphyllia.skyllia.sgbd.exceptions.DatabaseException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.euphyllia.skyllia.api.database;

import fr.euphyllia.skyllia.sgbd.exceptions.DatabaseException;

/**
* The {@code DatabaseInitializeQuery} class provides an abstract definition
* of an initialization query for a database.
* <p>
* Classes extending this abstract class should implement the {@link #init()} method
* to perform any necessary setup or configuration tasks, such as creating tables or
* verifying the database schema.
*/
public abstract class DatabaseInitializeQuery {

/**
* Initializes the database schema or performs any required setup operations.
*
* @return {@code true} if the initialization is successful, {@code false} otherwise
* @throws DatabaseException if an error occurs during the database initialization
*/
public abstract boolean init() throws DatabaseException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package fr.euphyllia.skyllia.api.database;

import fr.euphyllia.skyllia.api.skyblock.Island;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;

/**
* The {@code IslandDataQuery} class defines an abstract set of methods
* for querying and manipulating island data in a SkyBlock context.
* <p>
* Implementations should handle operations such as retrieving islands
* by owner or player, creating new islands, and obtaining island details.
*/
public abstract class IslandDataQuery {

/**
* Retrieves an {@link Island} by the UUID of its owner.
*
* @param playerId the UUID of the island owner
* @return a {@link CompletableFuture} that will complete with the retrieved {@link Island},
* or {@code null} if no matching island is found
*/
public abstract CompletableFuture<@Nullable Island> getIslandByOwnerId(UUID playerId);

/**
* Retrieves an {@link Island} by the UUID of a player who is a member of the island.
*
* @param playerId the UUID of the player
* @return a {@link CompletableFuture} that will complete with the retrieved {@link Island},
* or {@code null} if no matching island is found
*/
public abstract CompletableFuture<@Nullable Island> getIslandByPlayerId(UUID playerId);

/**
* Inserts a new island into the data source.
*
* @param futurIsland the {@link Island} to be inserted
* @return a {@link CompletableFuture} that will complete with {@code true} if the insertion
* was successful, or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> insertIslands(Island futurIsland);

/**
* Retrieves an {@link Island} by its UUID.
*
* @param islandId the UUID of the island
* @return a {@link CompletableFuture} that will complete with the retrieved {@link Island},
* or {@code null} if no island with the specified UUID is found
*/
public abstract CompletableFuture<@Nullable Island> getIslandByIslandId(UUID islandId);

/**
* Retrieves the maximum number of members allowed in the specified {@link Island}.
*
* @param island the {@link Island} to check
* @return a {@link CompletableFuture} that will complete with the maximum number of members
*/
public abstract CompletableFuture<Integer> getMaxMemberInIsland(Island island);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package fr.euphyllia.skyllia.api.database;

import fr.euphyllia.skyllia.api.skyblock.Island;
import fr.euphyllia.skyllia.api.skyblock.Players;
import fr.euphyllia.skyllia.api.skyblock.enums.RemovalCause;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* The {@code IslandMemberQuery} class defines an abstract set of methods
* for managing island members in a SkyBlock context.
* <p>
* Implementations should handle operations such as adding, updating,
* and removing members, as well as retrieving specific members or owners.
*/
public abstract class IslandMemberQuery {

/**
* Updates the membership information of a given player within the specified {@link Island}.
*
* @param island the {@link Island} the player belongs to
* @param players the player's membership details
* @return a {@link CompletableFuture} that completes with {@code true} if the update succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> updateMember(Island island, Players players);

/**
* Retrieves the {@link Players} object associated with a specified island and player UUID.
*
* @param island the {@link Island} to search
* @param playerId the UUID of the player
* @return a {@link CompletableFuture} that completes with the {@link Players} object
*/
public abstract CompletableFuture<Players> getPlayersIsland(Island island, UUID playerId);

/**
* Retrieves the {@link Players} object associated with a specified island and player name.
*
* @param island the {@link Island} to search
* @param playerName the player's name
* @return a {@link CompletableFuture} that completes with the {@link Players} object,
* or {@code null} if the player is not found
*/
public abstract CompletableFuture<@Nullable Players> getPlayersIsland(Island island, String playerName);

/**
* Retrieves all members in the specified {@link Island}.
*
* @param island the {@link Island} whose members are to be retrieved
* @return a {@link CompletableFuture} that completes with a list of {@link Players},
* or {@code null} if no members are found
*/
public abstract CompletableFuture<@Nullable CopyOnWriteArrayList<Players>> getMembersInIsland(Island island);

/**
* Retrieves the owner of the specified {@link Island}.
*
* @param island the {@link Island} to query
* @return a {@link CompletableFuture} that completes with the owner as a {@link Players} object,
* or {@code null} if no owner is found
*/
public abstract CompletableFuture<@Nullable Players> getOwnerInIslandId(Island island);

/**
* Adds a "member clear" record to track a player's removal cause.
*
* @param playerId the UUID of the player
* @param cause the {@link RemovalCause} for the removal
* @return a {@link CompletableFuture} that completes with {@code true} if the operation succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> addMemberClear(UUID playerId, RemovalCause cause);

/**
* Deletes a "member clear" record for the specified player and removal cause.
*
* @param playerId the UUID of the player
* @param cause the {@link RemovalCause} for the removal
* @return a {@link CompletableFuture} that completes with {@code true} if the deletion succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> deleteMemberClear(UUID playerId, RemovalCause cause);

/**
* Checks if a "member clear" record exists for the specified player and removal cause.
*
* @param playerId the UUID of the player
* @param cause the {@link RemovalCause} for the removal
* @return a {@link CompletableFuture} that completes with {@code true} if the record exists,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> checkClearMemberExist(UUID playerId, RemovalCause cause);

/**
* Deletes a member from the specified {@link Island}.
*
* @param island the {@link Island} from which the member will be removed
* @param oldMember the {@link Players} object representing the member to be removed
* @return a {@link CompletableFuture} that completes with {@code true} if the removal succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> deleteMember(Island island, Players oldMember);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package fr.euphyllia.skyllia.api.database;

import fr.euphyllia.skyllia.api.skyblock.Island;
import fr.euphyllia.skyllia.api.skyblock.model.PermissionRoleIsland;
import fr.euphyllia.skyllia.api.skyblock.model.RoleType;
import fr.euphyllia.skyllia.api.skyblock.model.permissions.PermissionsType;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;

/**
* The {@code IslandPermissionQuery} class defines an abstract set of methods
* for managing island permissions in a SkyBlock context.
* <p>
* Implementations should handle permission updates and retrieval for different
* roles and game rule configurations.
*/
public abstract class IslandPermissionQuery {

/**
* Updates the permissions for a specific {@link PermissionsType} and {@link RoleType}
* on the given island.
*
* @param island the {@link Island} whose permissions are to be updated
* @param permissionsType the type of permission to update
* @param roleType the role type (e.g., OWNER, MEMBER) for which permissions are updated
* @param permissions the new permission flags as a {@code long} value
* @return a {@link CompletableFuture} that completes with {@code true} if the update succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> updateIslandsPermission(
Island island,
PermissionsType permissionsType,
RoleType roleType,
long permissions
);

/**
* Retrieves the {@link PermissionRoleIsland} object representing permissions
* for the specified {@link PermissionsType} and {@link RoleType} on the given island.
*
* @param islandId the UUID of the island
* @param permissionsType the type of permission to retrieve
* @param roleType the role type (e.g., OWNER, MEMBER)
* @return a {@link CompletableFuture} that completes with the corresponding
* {@link PermissionRoleIsland} object
*/
public abstract CompletableFuture<PermissionRoleIsland> getIslandPermission(
UUID islandId,
PermissionsType permissionsType,
RoleType roleType
);

/**
* Retrieves the game rule value (usually represented as a long) for the specified island.
*
* @param island the {@link Island} whose game rule is to be retrieved
* @return a {@link CompletableFuture} that completes with the game rule value
*/
public abstract CompletableFuture<Long> getIslandGameRule(Island island);

/**
* Updates the game rule value for the specified island.
*
* @param island the {@link Island} whose game rule is to be updated
* @param value the new game rule value as a {@code long}
* @return a {@link CompletableFuture} that completes with {@code true} if the update succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> updateIslandGameRule(Island island, long value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package fr.euphyllia.skyllia.api.database;

import fr.euphyllia.skyllia.api.skyblock.Island;

import java.util.concurrent.CompletableFuture;

/**
* The {@code IslandUpdateQuery} class defines an abstract set of methods
* for updating various properties of an {@link Island} in a SkyBlock context.
* <p>
* Implementations should handle operations such as toggling the island status
* (disable/private), adjusting maximum members, and resizing the island.
*/
public abstract class IslandUpdateQuery {

/**
* Updates the disabled status of the specified island.
*
* @param island the {@link Island} to update
* @param disable {@code true} to disable the island, {@code false} to enable it
* @return a {@link CompletableFuture} that completes with {@code true} if the update succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> updateDisable(Island island, boolean disable);

/**
* Updates the private status of the specified island.
*
* @param island the {@link Island} to update
* @param privateIsland {@code true} to set the island as private, {@code false} to make it public
* @return a {@link CompletableFuture} that completes with {@code true} if the update succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> updatePrivate(Island island, boolean privateIsland);

/**
* Checks if the specified island is disabled.
*
* @param island the {@link Island} to check
* @return a {@link CompletableFuture} that completes with {@code true} if the island is disabled,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> isDisabledIsland(Island island);

/**
* Checks if the specified island is set to private.
*
* @param island the {@link Island} to check
* @return a {@link CompletableFuture} that completes with {@code true} if the island is private,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> isPrivateIsland(Island island);

/**
* Sets the maximum number of members for the specified island.
*
* @param island the {@link Island} to update
* @param newValue the new maximum number of members
* @return a {@link CompletableFuture} that completes with {@code true} if the update succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> setMaxMemberInIsland(Island island, int newValue);

/**
* Sets the size of the specified island.
*
* @param island the {@link Island} to update
* @param newValue the new size of the island (e.g., radius or diameter, depending on implementation)
* @return a {@link CompletableFuture} that completes with {@code true} if the update succeeds,
* or {@code false} otherwise
*/
public abstract CompletableFuture<Boolean> setSizeIsland(Island island, double newValue);
}
Loading

0 comments on commit 1de5e52

Please sign in to comment.