2022-07-20 13:18:57 +02:00
|
|
|
package fr.pandacube.lib.permissions;
|
2021-03-21 20:17:31 +01:00
|
|
|
|
2022-07-20 13:18:57 +02:00
|
|
|
import fr.pandacube.lib.db.SQLElement;
|
|
|
|
import fr.pandacube.lib.db.SQLField;
|
2021-03-21 20:17:31 +01:00
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
/**
|
|
|
|
* SQL Table to store the permissions data.
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
public class SQLPermissions extends SQLElement<SQLPermissions> {
|
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
/**
|
2023-06-20 00:15:46 +02:00
|
|
|
* Instantiate a new entry in the table.
|
2022-08-10 03:04:12 +02:00
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
public SQLPermissions() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
private SQLPermissions(int id) {
|
2021-03-21 20:17:31 +01:00
|
|
|
super(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String tableName() {
|
2021-03-21 22:40:05 +01:00
|
|
|
return "permissions";
|
2021-03-21 20:17:31 +01:00
|
|
|
}
|
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
/** The name of the entity (player id or group name). */
|
2021-03-21 20:17:31 +01:00
|
|
|
public static final SQLField<SQLPermissions, String> name = field(VARCHAR(64), false);
|
2022-08-10 03:04:12 +02:00
|
|
|
/** The entity type, based on {@link EntityType}. */
|
2021-03-21 20:17:31 +01:00
|
|
|
public static final SQLField<SQLPermissions, Integer> type = field(TINYINT, false);
|
2022-08-10 03:04:12 +02:00
|
|
|
/** The key of the data ("permission", "inheritance", …). */
|
2021-03-21 20:17:31 +01:00
|
|
|
public static final SQLField<SQLPermissions, String> key = field(VARCHAR(256), false);
|
2022-08-10 03:04:12 +02:00
|
|
|
/** The data value (permission node, name of inherited group, prefix/suffix, …). */
|
2021-03-21 20:17:31 +01:00
|
|
|
public static final SQLField<SQLPermissions, String> value = field(VARCHAR(256), false);
|
2022-08-10 03:04:12 +02:00
|
|
|
/** The server in which the permission apply. */
|
2021-03-21 20:17:31 +01:00
|
|
|
public static final SQLField<SQLPermissions, String> server = field(VARCHAR(64), true);
|
2022-08-10 03:04:12 +02:00
|
|
|
/** The world in which the permission apply. */
|
2021-03-21 20:17:31 +01:00
|
|
|
public static final SQLField<SQLPermissions, String> world = field(VARCHAR(64), true);
|
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
/**
|
|
|
|
* All possible type of entity type.
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
public enum EntityType {
|
2022-08-10 03:04:12 +02:00
|
|
|
/**
|
|
|
|
* User entity type.
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
User,
|
2022-08-10 03:04:12 +02:00
|
|
|
/**
|
|
|
|
* Group entity type.
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
Group;
|
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
/**
|
|
|
|
* Returns the database value of this entity type.
|
|
|
|
* @return the database value of this entity type.
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
public int getCode() {
|
|
|
|
return ordinal();
|
|
|
|
}
|
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
/**
|
|
|
|
* Gets the {@link EntityType} corresponding to the database value.
|
|
|
|
* @param code the database value.
|
|
|
|
* @return the {@link EntityType} corresponding to the database value.
|
|
|
|
*/
|
2021-03-21 20:17:31 +01:00
|
|
|
public static EntityType getByCode(int code) {
|
|
|
|
if (code >= 0 && code < values().length)
|
|
|
|
return values()[code];
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|