Package de.murmelmeister.murmelapi
Class MurmelAPI
java.lang.Object
de.murmelmeister.murmelapi.MurmelAPI
The MurmelAPI main class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidEstablishes a connection to the database using the provided credentials and URL, and initializes necessary configurations.static voiddeleteFullUser(int userId) static voiddeleteUser(int userId) static voidDisconnects the application from the currently connected database.static ActiveSessionRetrieves the active session instance associated with the application.static DatabaseReturns the current instance of the database used by the application.static StringRetrieves the name of the currently configured database.static SimpleDateFormatRetrieves the current date format used by the application.static GroupgetGroup()Retrieves the instance of theGroupobject.static LoginHistoryRetrieves the instance of the LoginHistory provider.static PermissionRetrieves the current permission instance for the application.static PermissiongetPermission(Group group, User user) Retrieves the Permission instance for the specified group and user.static PlayTimeRetrieves the singleton instance of the PlayTime interface, initializing it if necessary.static PunishmentIPRetrieves the default instance of PunishmentIP using the default punishment reason and punishment log.static PunishmentIPgetPunishmentIP(PunishmentReason reason, PunishmentLog log) Retrieves the PunishmentIP instance associated with the provided punishment reason and log.static PunishmentLogRetrieves the default punishment log associated with the system.static PunishmentLoggetPunishmentLog(PunishmentReason reason) Retrieves the punishment log associated with the specified punishment reason.static PunishmentReasonRetrieves the PunishmentReason instance, initializing it if necessary.static PunishmentUserRetrieves a `PunishmentUser` object by internally obtaining the required `PunishmentReason` and `PunishmentLog` instances through corresponding methods.static PunishmentUsergetPunishmentUser(PunishmentReason reason, PunishmentLog log) Retrieves the instance ofPunishmentUser, initializing it if necessary, based on the providedPunishmentReasonandPunishmentLog.static UsergetUser()Retrieves the singleton instance of theUserobject.static voidsetDatabaseName(String databaseName) Updates the name of the database used by the application.static voidsetDateFormat(SimpleDateFormat dateFormat) Sets the date format for use within the application.static voidsetup()Sets up the necessary database tables, procedures, and initializes providers for the application.
-
Constructor Details
-
MurmelAPI
public MurmelAPI()
-
-
Method Details
-
connect
Establishes a connection to the database using the provided credentials and URL, and initializes necessary configurations.- Parameters:
url- the database URL to connect touser- the username for authenticationpassword- the password for authentication
-
disconnect
public static void disconnect()Disconnects the application from the currently connected database. This method should be invoked when the database connection is no longer needed. It ensures proper disconnection and resource cleanup related to the database connection. -
setup
public static void setup()Sets up the necessary database tables, procedures, and initializes providers for the application.This method performs the initial configuration required for the application to function correctly. It includes the creation of database tables and stored procedures for various data entities, as well as initializing provider instances for managing these entities.
The setup process involves: - Creating the necessary tables and procedures for handling users, groups, permissions, bans, mutes, login histories, play times, edit logs, and related data. - Initializing instances of providers and services such as editLogger, loginHistory, user, group, permission, ban, and mute for subsequent use in the application.
This method is expected to be called once during the application's initialization phase.
-
deleteUser
public static void deleteUser(int userId) -
deleteFullUser
public static void deleteFullUser(int userId) -
getDatabaseName
Retrieves the name of the currently configured database.- Returns:
- The name of the database as a String
-
setDatabaseName
Updates the name of the database used by the application.- Parameters:
databaseName- The name of the database to be set
-
getDateFormat
Retrieves the current date format used by the application.- Returns:
- The SimpleDateFormat instance representing the currently configured date format.
-
setDateFormat
Sets the date format for use within the application.- Parameters:
dateFormat- The date format to be used, represented as aSimpleDateFormatinstance
-
getDatabase
Returns the current instance of the database used by the application.- Returns:
- The current instance of the database
-
getLoginHistory
Retrieves the instance of the LoginHistory provider. If the provider is not already initialized, a new LoginHistoryProvider instance is created using the pre-configured database.- Returns:
- The LoginHistory instance, representing the login history data provider.
-
getActiveSession
Retrieves the active session instance associated with the application. If no active session exists, a new one is initialized usingActiveSessionProvider.- Returns:
- The
ActiveSessioninstance representing the application's active session.
-
getUser
Retrieves the singleton instance of theUserobject. If the instance does not already exist, it is initialized using theUserProviderwith theDATABASE.- Returns:
- The singleton instance of the
Userobject
-
getGroup
Retrieves the instance of theGroupobject. If theGroupinstance has not been initialized, this method initializes it using theGroupProviderwith the configuredDATABASE.- Returns:
- The
Groupinstance for managing group-related operations.
-
getPlayTime
Retrieves the singleton instance of the PlayTime interface, initializing it if necessary.- Returns:
- The singleton instance of the PlayTime interface for managing and manipulating user play times.
-
getPermission
Retrieves the Permission instance for the specified group and user. If the Permission instance has not been initialized, it creates a new PermissionProvider instance using the given group and user, and returns it.- Parameters:
group- The group for which the permissions are being retrieved.user- The user for whom the permissions are being retrieved.- Returns:
- The Permission instance corresponding to the specified group and user.
-
getPermission
Retrieves the current permission instance for the application. This method initializes the permission instance if it has not been previously created, using the group and user instances.- Returns:
- The initialized or existing
Permissioninstance based on the current group and user.
-
getPunishmentReason
Retrieves the PunishmentReason instance, initializing it if necessary. This method ensures a singleton-like behavior for the PunishmentReason instance by lazily initializing it through the PunishmentReasonProvider using the DATABASE field, if it has not already been instantiated.- Returns:
- The current instance of PunishmentReason
-
getPunishmentLog
Retrieves the punishment log associated with the specified punishment reason. If the punishment log has not been initialized, it will create a new instance using the provided reason and the database configuration.- Parameters:
reason- The reason for the punishment to retrieve or generate the punishment log- Returns:
- The instance of the punishment log corresponding to the given punishment reason
-
getPunishmentLog
Retrieves the default punishment log associated with the system. This method internally uses the default punishment reason to obtain the punishment log.- Returns:
- The punishment log associated with the default punishment reason
-
getPunishmentIP
Retrieves the PunishmentIP instance associated with the provided punishment reason and log. If the instance is not initialized, it creates a new PunishmentIPProvider using the database, reason, and log.- Parameters:
reason- The PunishmentReason object used to associate specific punishment logiclog- The PunishmentLog object that tracks punishment-related actions and history- Returns:
- The PunishmentIP instance for managing punishment-related IP operations
-
getPunishmentIP
Retrieves the default instance of PunishmentIP using the default punishment reason and punishment log.- Returns:
- The default PunishmentIP instance, constructed using the default punishment reason and punishment log.
-
getPunishmentUser
Retrieves the instance ofPunishmentUser, initializing it if necessary, based on the providedPunishmentReasonandPunishmentLog.- Parameters:
reason- The reason associated with the punishmentlog- The log containing details of the punishment- Returns:
- The instance of
PunishmentUserassociated with the given reason and log
-
getPunishmentUser
Retrieves a `PunishmentUser` object by internally obtaining the required `PunishmentReason` and `PunishmentLog` instances through corresponding methods.- Returns:
- A `PunishmentUser` object constructed using the retrieved `PunishmentReason` and `PunishmentLog`
-