Class Permissions

java.lang.Object
com.minecolonies.core.colony.permissions.Permissions
All Implemented Interfaces:
IPermissions

public class Permissions extends Object implements IPermissions
Colony Permissions System.
  • Constructor Details

    • Permissions

      public Permissions(@NotNull @NotNull Colony colony)
      Saves the permissionMap with allowed actions.
      Parameters:
      colony - the colony this permissionMap object belongs to.
  • Method Details

    • setPermission

      public final boolean setPermission(Rank rank, @NotNull @NotNull Action action, boolean enable)
      Sets the rank for a specific action.
      Specified by:
      setPermission in interface IPermissions
      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: IPermissions
      Alters the permission through an actor, checks for allowance before altering.
      Specified by:
      alterPermission in interface IPermissions
      Parameters:
      actor - to check
      rank - rank to edit
      action - action to set
      enable - add/remove permission
      Returns:
      success/failure
    • canAlterPermission

      public boolean canAlterPermission(Rank actor, Rank rank, @NotNull @NotNull Action action)
      Description copied from interface: IPermissions
      Check if a specific permission can be altered.
      Specified by:
      canAlterPermission in interface IPermissions
      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:
      restoreOwnerIfNull in interface IPermissions
    • getOwnerEntry

      @Nullable public Map.Entry<UUID,ColonyPlayer> getOwnerEntry()
      Compute the owner of a colony.

      Can be quite expensive in colonies with many players.

      Specified by:
      getOwnerEntry in interface IPermissions
      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:
      setOwner in interface IPermissions
      Parameters:
      player - the player to set.
      Returns:
      true if successful.
    • setOwnerAbandoned

      public void setOwnerAbandoned()
      Change the owner of a colony to [abandoned]
      Specified by:
      setOwnerAbandoned in interface IPermissions
    • getOwner

      @NotNull public @NotNull UUID getOwner()
      Returns the owner of this permission instance.
      Specified by:
      getOwner in interface IPermissions
      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

      @NotNull public @NotNull Map<UUID,ColonyPlayer> getPlayers()
      Description copied from interface: IPermissions
      Returns an unmodifiable map of the players list.
      Specified by:
      getPlayers in interface IPermissions
      Returns:
      map of UUIDs and player objects.
    • hasPermission

      public boolean hasPermission(Rank rank, @NotNull @NotNull Action action)
      Checks if a rank can perform an action.
      Specified by:
      hasPermission in interface IPermissions
      Parameters:
      rank - Rank you want to check.
      action - Action you want to perform.
      Returns:
      true if rank has permission for action, otherwise false.
    • getPlayersByRank

      public Set<ColonyPlayer> getPlayersByRank(Rank rank)
      Gets all player by a certain rank.
      Specified by:
      getPlayersByRank in interface IPermissions
      Parameters:
      rank - the rank.
      Returns:
      set of players.
    • getPlayersByRank

      public Set<ColonyPlayer> getPlayersByRank(@NotNull @NotNull Set<Rank> ranks)
      Gets all player by a set of ranks.
      Specified by:
      getPlayersByRank in interface IPermissions
      Parameters:
      ranks - the set of Ranks.
      Returns:
      set of players.
    • getFilteredPlayers

      public Set<ColonyPlayer> getFilteredPlayers(@NotNull @NotNull Predicate<Rank> predicate)
      Specified by:
      getFilteredPlayers in interface IPermissions
    • 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:
      hasPermission in interface IPermissions
      Parameters:
      player - Player player.
      action - Action action.
      Returns:
      true if player has permissionMap, otherwise false.
    • getRank

      public Rank getRank(@NotNull @NotNull net.minecraft.world.entity.player.Player player)
      Description copied from interface: IPermissions
      Get the rank of a certain player.
      Specified by:
      getRank in interface IPermissions
      Parameters:
      player - the player.
      Returns:
      the rank.
    • setPlayerRank

      public boolean setPlayerRank(UUID id, Rank rank, net.minecraft.world.level.Level world)
      Sets the player's rank to a given rank.
      Specified by:
      setPlayerRank in interface IPermissions
      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

      public boolean addPlayer(@NotNull @NotNull UUID id, String name, Rank rank)
      Adds a player to the rankings.
      Specified by:
      addPlayer in interface IPermissions
      Parameters:
      id - UUID of the player..
      rank - Desired rank.
      name - name of the player.
      Returns:
      True if successful, otherwise false.
    • getRank

      @NotNull public @NotNull Rank getRank(UUID id)
      Returns the rank belonging to the UUID.
      Specified by:
      getRank in interface IPermissions
      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:
      addPlayer in interface IPermissions
      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

      public boolean addPlayer(@NotNull @NotNull com.mojang.authlib.GameProfile gameprofile, Rank rank)
      Adds a player to the rankings.
      Specified by:
      addPlayer in interface IPermissions
      Parameters:
      gameprofile - GameProfile of the player.
      rank - Desired rank.
      Returns:
      True if successful, otherwise false.
    • removePlayer

      public boolean removePlayer(UUID id)
      Remove a player from the permissionMap.
      Specified by:
      removePlayer in interface IPermissions
      Parameters:
      id - UUID of the player.
      Returns:
      True if successful, otherwise false.
    • getOwnerName

      @Nullable public @Nullable String getOwnerName()
      Returns the name of the owner of this permission instance.
      Specified by:
      getOwnerName in interface IPermissions
      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 - FriendlyByteBuf to write to.
      viewerRank - Rank of the viewer.
    • isColonyMember

      public boolean isColonyMember(@NotNull @NotNull net.minecraft.world.entity.player.Player player)
      Description copied from interface: IPermissions
      Returns whether the player is a member of the colony.
      Specified by:
      isColonyMember in interface IPermissions
      Parameters:
      player - Player to check.
      Returns:
      true if the player is a member of the colony.
    • getRankOwner

      public Rank getRankOwner()
      Get rank instance of owner
      Specified by:
      getRankOwner in interface IPermissions
      Returns:
      the rank
    • getRankOfficer

      public Rank getRankOfficer()
      Get rank instance of officer
      Specified by:
      getRankOfficer in interface IPermissions
      Returns:
      the rank
    • getRankHostile

      public Rank getRankHostile()
      Get rank instance of hostile
      Specified by:
      getRankHostile in interface IPermissions
      Returns:
      the rank
    • getRankFriend

      public Rank getRankFriend()
      Get rank instance of friend
      Specified by:
      getRankFriend in interface IPermissions
      Returns:
      the rank
    • getRankNeutral

      public Rank getRankNeutral()
      Get rank instance of neutral
      Specified by:
      getRankNeutral in interface IPermissions
      Returns:
      the rank
    • getRank

      public Rank getRank(int id)
      Description copied from interface: IPermissions
      Returns the rank with the given ID
      Specified by:
      getRank in interface IPermissions
      Parameters:
      id - the id
      Returns:
      the rank
    • getRanks

      public Map<Integer,Rank> getRanks()
      Get a map of all ranks with their according ID as key
      Specified by:
      getRanks in interface IPermissions
      Returns:
      the ranks
    • addRank

      public void addRank(String name)
      Create a new rank instance with the given name, auto assign lowest unused ID, no permissions
      Specified by:
      addRank in interface IPermissions
      Parameters:
      name - the name of the rank
    • removeRank

      public void removeRank(Rank rank)
      Remove the given rank, if it is not an initial rank Set all players with the given rank to neutral
      Specified by:
      removeRank in interface IPermissions
      Parameters:
      rank - the rank to remove