2020-07-31 22:31:58 +02:00
|
|
|
package net.minestom.server.permission;
|
|
|
|
|
|
|
|
import net.minestom.server.command.CommandSender;
|
2020-08-10 21:42:54 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-12-10 02:56:56 +01:00
|
|
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
2020-07-31 22:31:58 +02:00
|
|
|
|
|
|
|
/**
|
2020-11-02 02:53:12 +01:00
|
|
|
* Representation of a permission granted to a {@link CommandSender}.
|
2020-12-11 21:42:32 +01:00
|
|
|
* Each permission has a string representation used as an identifier, and an optional
|
|
|
|
* {@link NBTCompound} used to store additional data.
|
|
|
|
* <p>
|
|
|
|
* The class is immutable.
|
2020-07-31 22:31:58 +02:00
|
|
|
*/
|
2020-12-10 02:56:56 +01:00
|
|
|
public class Permission {
|
|
|
|
|
2020-12-11 03:19:25 +01:00
|
|
|
private final String permissionName;
|
|
|
|
private final NBTCompound data;
|
2020-12-10 02:56:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new permission object with optional data.
|
|
|
|
*
|
|
|
|
* @param permissionName the name of the permission
|
|
|
|
* @param data the optional data of the permission
|
|
|
|
*/
|
|
|
|
public Permission(@NotNull String permissionName, @Nullable NBTCompound data) {
|
|
|
|
this.permissionName = permissionName;
|
|
|
|
this.data = data;
|
|
|
|
}
|
2020-07-31 22:31:58 +02:00
|
|
|
|
|
|
|
/**
|
2020-12-10 02:56:56 +01:00
|
|
|
* Creates a new permission object without additional data
|
2020-09-24 01:50:25 +02:00
|
|
|
*
|
2020-12-10 02:56:56 +01:00
|
|
|
* @param permissionName the name of the permission
|
2020-07-31 22:31:58 +02:00
|
|
|
*/
|
2020-12-10 02:56:56 +01:00
|
|
|
public Permission(@NotNull String permissionName) {
|
|
|
|
this(permissionName, null);
|
|
|
|
}
|
2020-07-31 22:31:58 +02:00
|
|
|
|
2020-08-10 21:42:54 +02:00
|
|
|
/**
|
2020-12-10 02:56:56 +01:00
|
|
|
* Gets the name of the permission.
|
2020-09-24 01:50:25 +02:00
|
|
|
*
|
2020-12-10 02:56:56 +01:00
|
|
|
* @return the permission name
|
2020-08-10 21:42:54 +02:00
|
|
|
*/
|
2020-12-10 02:56:56 +01:00
|
|
|
@NotNull
|
|
|
|
public String getPermissionName() {
|
|
|
|
return permissionName;
|
2020-09-24 01:50:25 +02:00
|
|
|
}
|
2020-08-10 21:42:54 +02:00
|
|
|
|
|
|
|
/**
|
2020-12-10 02:56:56 +01:00
|
|
|
* Gets the data associated to this permission.
|
2020-09-24 01:50:25 +02:00
|
|
|
*
|
2020-12-10 02:56:56 +01:00
|
|
|
* @return the nbt data of this permission, can be null if not any
|
2020-08-10 21:42:54 +02:00
|
|
|
*/
|
2020-12-10 02:56:56 +01:00
|
|
|
@Nullable
|
|
|
|
public NBTCompound getNBTData() {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) return true;
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
Permission that = (Permission) o;
|
|
|
|
return permissionName.equals(that.permissionName) && Objects.equals(data, that.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return Objects.hash(permissionName, data);
|
2020-08-10 21:42:54 +02:00
|
|
|
}
|
2020-07-31 22:31:58 +02:00
|
|
|
}
|