Class Permissions
java.lang.Object
com.minecolonies.core.colony.permissions.Permissions
- All Implemented Interfaces:
IPermissions
Colony Permissions System.
-
Field Summary
Fields inherited from interface com.minecolonies.api.colony.permissions.IPermissions
FRIEND_RANK_ID, HOSTILE_RANK_ID, NEUTRAL_RANK_ID, OFFICER_RANK_ID, OWNER_RANK_ID -
Constructor Summary
ConstructorsConstructorDescriptionPermissions(@NotNull Colony colony) Saves the permissionMap with allowed actions. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a player to the rankings.booleanAdd a player to the rankings.booleanAdds a player to the rankings.voidCreate a new rank instance with the given name, auto assign lowest unused ID, no permissionsbooleanalterPermission(Rank actor, Rank rank, @NotNull Action action, boolean enable) Alters the permission through an actor, checks for allowance before altering.booleancanAlterPermission(Rank actor, Rank rank, @NotNull Action action) Check if a specific permission can be altered.voidMarks instance not dirty.getFilteredPlayers(@NotNull Predicate<Rank> predicate) @NotNull UUIDgetOwner()Returns the owner of this permission instance.Compute the owner of a colony.@Nullable StringReturns the name of the owner of this permission instance.@NotNull Map<UUID,ColonyPlayer> Returns an unmodifiable map of the players list.getPlayersByRank(@NotNull Set<Rank> ranks) Gets all player by a set of ranks.getPlayersByRank(Rank rank) Gets all player by a certain rank.getRank(int id) Returns the rank with the given IDgetRank(@NotNull net.minecraft.world.entity.player.Player player) Get the rank of a certain player.@NotNull RankReturns the rank belonging to the UUID.Get rank instance of friendGet rank instance of hostileGet rank instance of neutralGet rank instance of officerGet rank instance of ownergetRanks()Get a map of all ranks with their according ID as keybooleanhasPermission(@NotNull net.minecraft.world.entity.player.Player player, @NotNull Action action) Checks if the player has the permission of an action.booleanhasPermission(Rank rank, @NotNull Action action) Checks if a rank can perform an action.booleanisColonyMember(@NotNull net.minecraft.world.entity.player.Player player) Returns whether the player is a member of the colony.booleanisDirty()Returns if the instance is dirty.voidloadPermissions(@NotNull net.minecraft.nbt.CompoundTag compound) Reads the permissionMap from a NBT.booleanremovePlayer(UUID id) Remove a player from the permissionMap.voidremoveRank(Rank rank) Remove the given rank, if it is not an initial rank Set all players with the given rank to neutralvoidRestores the owner from other variables if he is null on loading.voidsavePermissions(@NotNull net.minecraft.nbt.CompoundTag compound) Save the permissionMap to a NBT.voidserializeViewNetworkData(@NotNull net.minecraft.network.FriendlyByteBuf buf, @NotNull Rank viewerRank) Serializes network data.booleansetOwner(net.minecraft.world.entity.player.Player player) Change the owner of a colony.voidChange the owner of a colony to [abandoned]final booleansetPermission(Rank rank, @NotNull Action action, boolean enable) Sets the rank for a specific action.booleansetPlayerRank(UUID id, Rank rank, net.minecraft.world.level.Level world) Sets the player's rank to a given rank.
-
Constructor Details
-
Permissions
Saves the permissionMap with allowed actions.- Parameters:
colony- the colony this permissionMap object belongs to.
-
-
Method Details
-
setPermission
Sets the rank for a specific action.- Specified by:
setPermissionin interfaceIPermissions- Parameters:
rank- Desired rank.action- Action that should have desired rank.enable- or disable permission- Returns:
-
alterPermission
public boolean alterPermission(Rank actor, Rank rank, @NotNull @NotNull Action action, boolean enable) Description copied from interface:IPermissionsAlters the permission through an actor, checks for allowance before altering.- Specified by:
alterPermissionin interfaceIPermissions- Parameters:
actor- to checkrank- rank to editaction- action to setenable- add/remove permission- Returns:
- success/failure
-
canAlterPermission
Description copied from interface:IPermissionsCheck if a specific permission can be altered.- Specified by:
canAlterPermissionin interfaceIPermissions- Parameters:
actor- acting rank.rank- the rank to check it for.action- the action to check.- Returns:
- true if so.
-
loadPermissions
public void loadPermissions(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound) Reads the permissionMap from a NBT.- Parameters:
compound- NBT to read from.
-
restoreOwnerIfNull
public void restoreOwnerIfNull()Restores the owner from other variables if he is null on loading.- Specified by:
restoreOwnerIfNullin interfaceIPermissions
-
getOwnerEntry
Compute the owner of a colony.Can be quite expensive in colonies with many players.
- Specified by:
getOwnerEntryin interfaceIPermissions- Returns:
- the corresponding entry or null.
-
setOwner
public boolean setOwner(net.minecraft.world.entity.player.Player player) Change the owner of a colony.- Specified by:
setOwnerin interfaceIPermissions- Parameters:
player- the player to set.- Returns:
- true if successful.
-
setOwnerAbandoned
public void setOwnerAbandoned()Change the owner of a colony to [abandoned]- Specified by:
setOwnerAbandonedin interfaceIPermissions
-
getOwner
Returns the owner of this permission instance.- Specified by:
getOwnerin interfaceIPermissions- Returns:
- UUID of the owner.
-
savePermissions
public void savePermissions(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound) Save the permissionMap to a NBT.- Parameters:
compound- NBT to write to.
-
getPlayers
Description copied from interface:IPermissionsReturns an unmodifiable map of the players list.- Specified by:
getPlayersin interfaceIPermissions- Returns:
- map of UUIDs and player objects.
-
hasPermission
Checks if a rank can perform an action.- Specified by:
hasPermissionin interfaceIPermissions- Parameters:
rank- Rank you want to check.action- Action you want to perform.- Returns:
- true if rank has permission for action, otherwise false.
-
getPlayersByRank
Gets all player by a certain rank.- Specified by:
getPlayersByRankin interfaceIPermissions- Parameters:
rank- the rank.- Returns:
- set of players.
-
getPlayersByRank
Gets all player by a set of ranks.- Specified by:
getPlayersByRankin interfaceIPermissions- Parameters:
ranks- the set of Ranks.- Returns:
- set of players.
-
getFilteredPlayers
- Specified by:
getFilteredPlayersin interfaceIPermissions
-
hasPermission
public boolean hasPermission(@NotNull @NotNull net.minecraft.world.entity.player.Player player, @NotNull @NotNull Action action) Checks if the player has the permission of an action.- Specified by:
hasPermissionin interfaceIPermissions- Parameters:
player-Playerplayer.action-Actionaction.- Returns:
- true if player has permissionMap, otherwise false.
-
getRank
Description copied from interface:IPermissionsGet the rank of a certain player.- Specified by:
getRankin interfaceIPermissions- Parameters:
player- the player.- Returns:
- the rank.
-
setPlayerRank
Sets the player's rank to a given rank.- Specified by:
setPlayerRankin interfaceIPermissions- Parameters:
id- UUID of the player of the new oldRank.rank- Desired rank.world- the world the player is in.- Returns:
- True if successful, otherwise false.
-
addPlayer
Adds a player to the rankings.- Specified by:
addPlayerin interfaceIPermissions- Parameters:
id- UUID of the player..rank- Desired rank.name- name of the player.- Returns:
- True if successful, otherwise false.
-
getRank
Returns the rank belonging to the UUID.- Specified by:
getRankin interfaceIPermissions- Parameters:
id- UUID that you want to check rank of.- Returns:
- Rank of the UUID.
-
addPlayer
public boolean addPlayer(@NotNull @NotNull String player, Rank rank, net.minecraft.world.level.Level world) Add a player to the rankings.- Specified by:
addPlayerin interfaceIPermissions- Parameters:
player- String playername of the player to add.rank- Rank desired starting rank.world- the world the player is in.- Returns:
- True if successful, otherwise false.
-
addPlayer
Adds a player to the rankings.- Specified by:
addPlayerin interfaceIPermissions- Parameters:
gameprofile- GameProfile of the player.rank- Desired rank.- Returns:
- True if successful, otherwise false.
-
removePlayer
Remove a player from the permissionMap.- Specified by:
removePlayerin interfaceIPermissions- Parameters:
id- UUID of the player.- Returns:
- True if successful, otherwise false.
-
getOwnerName
Returns the name of the owner of this permission instance.- Specified by:
getOwnerNamein interfaceIPermissions- Returns:
- Name of the owner.
-
isDirty
public boolean isDirty()Returns if the instance is dirty.- Returns:
- True if dirty, otherwise false.
-
clearDirty
public void clearDirty()Marks instance not dirty. -
serializeViewNetworkData
public void serializeViewNetworkData(@NotNull @NotNull net.minecraft.network.FriendlyByteBuf buf, @NotNull @NotNull Rank viewerRank) Serializes network data.- Parameters:
buf-FriendlyByteBufto write to.viewerRank- Rank of the viewer.
-
isColonyMember
public boolean isColonyMember(@NotNull @NotNull net.minecraft.world.entity.player.Player player) Description copied from interface:IPermissionsReturns whether the player is a member of the colony.- Specified by:
isColonyMemberin interfaceIPermissions- Parameters:
player-Playerto check.- Returns:
- true if the player is a member of the colony.
-
getRankOwner
Get rank instance of owner- Specified by:
getRankOwnerin interfaceIPermissions- Returns:
- the rank
-
getRankOfficer
Get rank instance of officer- Specified by:
getRankOfficerin interfaceIPermissions- Returns:
- the rank
-
getRankHostile
Get rank instance of hostile- Specified by:
getRankHostilein interfaceIPermissions- Returns:
- the rank
-
getRankFriend
Get rank instance of friend- Specified by:
getRankFriendin interfaceIPermissions- Returns:
- the rank
-
getRankNeutral
Get rank instance of neutral- Specified by:
getRankNeutralin interfaceIPermissions- Returns:
- the rank
-
getRank
Description copied from interface:IPermissionsReturns the rank with the given ID- Specified by:
getRankin interfaceIPermissions- Parameters:
id- the id- Returns:
- the rank
-
getRanks
Get a map of all ranks with their according ID as key- Specified by:
getRanksin interfaceIPermissions- Returns:
- the ranks
-
addRank
Create a new rank instance with the given name, auto assign lowest unused ID, no permissions- Specified by:
addRankin interfaceIPermissions- Parameters:
name- the name of the rank
-
removeRank
Remove the given rank, if it is not an initial rank Set all players with the given rank to neutral- Specified by:
removeRankin interfaceIPermissions- Parameters:
rank- the rank to remove
-